开发者

What are the signature possibilities for multidimensional arrays with data objects?

开发者 https://www.devze.com 2023-03-13 20:13 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消