What are the signature possibilities for multidimensional arrays with data objects?
A recent post gives an example of targeting a value in a nest of multidimensional arrays with data objects in a framework. The answer for this question turned out a long string of names connected with "->" operators similar to this (with actual named objects and arrays where here I use generic terms):
$object->object->object->array[index]->array['key']['key']->array['key']['key']
Unfortunately the post closed before I could post my clarifying question :( I've seen examples similar to this,
$object->($object->property)
...which use开发者_开发知识库s parenthesis. Are there other syntax variations? What are the syntax restrictions to writing these statements in PHP?
$object->($object->property)
Is not working PHP code. It will give syntax error. But probably you meant:
$object->{$object->property}
Which works like this:
$object->foo = 'bar';
$object->property = 'foo';
echo $object->property; # foo
echo $object->{$object->property}; # bar
It will first evaluate what's inside the parenthesis ({$object->property}
) which is foo
and then return $object->foo
which is bar
.
精彩评论