I see that it is possible to calculate a value inside an associative array like this:

$testarray = array(
"x"=>2,
"y"=>5,
"z"=>(5*2);

 print_r($testarray); //Array ( [x] => 2 [y] => 5 [z] => 10 )

Is it possible to do it in a manner like this:

$testarray = array(
"x"=>2,
"y"=>5,
"z"=>x*y);
有帮助吗?

解决方案

No. You cannot access an array's elements before the array is defined.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top