Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array items and & address operator...

Status
Not open for further replies.

shadedecho

Programmer
Joined
Oct 4, 2002
Messages
336
Location
US
is there anyway to get a reference to an actual array item and assign that to another variable? like this:

Code:
$arr = array("a" => array("a_1" => 1, "a_2" => 2), "b" => "b_1");

$a = &{$arr["a"]};

notice that $arr["a"] is itself an array, so one would think that you could actually get an address reference to that (sub) array. However, every syntax I try to do gives me PHP errors. I have tried {} and () around the array item, still no go.

anyone know how to do this?
 
good grief! how incredibly simple. yes that is exactly what I was getting at.

I for some reason felt i needed to help the "binding order" of the operators so that the & knew to get the address of the whole
Code:
$a[1]
instead of just the $a that it was immediately adjacent to. I guess PHP already says that
Code:
[]
binds before &. cool, thanks!

btw, doesn't it seem strange that having the () or the {} around the
Code:
$a[1]
was causing errors?
 
that's my point, sleipnir, try your above example, but do
Code:
&($a[1])
or
Code:
&{$a[1]}
instead of just
Code:
&$a[1]
and it produces an error about expecting a different data type, something like T_STRING or something like that.

wonder why this is?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top