PHP: can one determine the parent array's name and key from a reference to an array element? -


let's assume have array this

$arr=array(array('a'=>1,'b'=>2),array('c'=>3,'d'=>4)); 

and reference 1 of elements

$element=&$arr[1]['c']; 

my question is possible original array using reference alone? parent array in way without knowing name... useful me in more complex scenario.

no, it's not possible. being "reference" (as php calls it; it's copy inhibitor) doesn't @ in matter. you'll have store original array element.

$elarrpair = array(     "container" => $arr,     "element"   => &$arr[1]['c'], ); 

this way can change element $elarrpair["element"] = $newvalue , still able access container.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -