How to make a "reference" to an array by string in php

Active3 hr before
Viewed126 times

2 Answers


What References Are Not, References Explained , Predefined Interfaces and Classes

Another example of something to watch out
for when using references with arrays.It seems that even an usused reference to an array cell modifies the * source * of the reference.Strange behavior
for an assignment statement(is this why I 've seen it written as an =& operator?  - although this doesn'
   t happen with regular variables). < ? php $array1 = array(1, 2);
$x = & $array1[1]; // Unused reference    $array2 = $array1;  // reference now also applies to $array2 !    $array2[1]=22;      // (changing [0] will not affect $array1)    print_r($array1);?>Produces:    Array    (    [0] => 1    [1] => 22    // var_dump() will show the & here    )I fixed my bug by rewriting the code without references, but it can also be fixed with the unset() function:<?php    $array1 = array(1,2);    $x = &$array1[1];    $array2 = $array1;    unset($x); // Array copy is now unaffected by above reference    $array2[1]=22;    print_r($array1);?>Produces:    Array    (    [0] => 1    [1] => 2    )
load more v

How can I make those messages disappear? Because the entire code is working(I get the desired output).,Connect and share knowledge within a single location that is structured and easy to search., Reconnecting with a previous professor then asking right away for a reference letter , Can you see the shadow of a spaceship on the Moon while looking towards the Earth?

You are passing the result of a function call as an argument. You aren't passing a variable.

$vars = get_defined_vars();
echo var_name($a, $vars);

Other "reference-string" queries related to "How to make a "reference" to an array by string in php"