No. You cannot access an array's elements before the array is defined.
Is it possible to perform calculations inside a PHP associative array?
-
30-09-2022 - |
题
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);
解决方案
不隶属于 StackOverflow