RE: Referencing Multi Dimensional Arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm



On 01 December 2004 17:31, Robinson, Matthew wrote:

> I have a search function:
> 
> $search_result = multi_array_search($net_array,"needle");
> 
> now search_result equals an array of keys to locate the
> needle, this is
> variable in count.
> 
> Sometimes the array of keys is 3 entries other times 5, I
> want a way of
> taking those entries and being able to do something like:
> 
> $net_array[multi-dimensional-key] = value;
> 
> where sometimes it might be in longhand:
> 
> $net_array["net1"]["net2"]["address1"]
> 
> or other times:
> 
> $net_array["net1"]["address1"]
> 
> but you don't know how deep you're going until the search returns you
> the keys. 

Coming to this a bit late, but one possibility might be:

   $result = &$net_array;
   foreach ($search_result as $index):
      $result = &$result[$index];
   endforeach;
   // $result is now a reference to the array element.

Alternatively, wouldn't it be possible for the search function to return
that reference itself?  Or do you particularly want to know what the
sequence of accessor keys is?

Usual caveats apply: this is all off the top of my head, and completely
untested!

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@xxxxxxxxxxxxxx
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux