3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function o($num) { return (object) array('num' => $num); } $arr = array( 14 => array('x' => o(1), 'oele' => array(o(1), o(2), o(3), o(4))), 91 => array('x' => o(1), 'oele' => array(o(9), o(8), o(7), o(6))), ); foreach ( $arr as $i => &$session ) { $session['boele']['one'] = 4; // works $session['boele']['two'] = array_reduce($session['oele'], function($sum, $app) use ($session) { return $sum + $app->num * $session['x']->num; }, 0); // don't works unset($session); } print_r($arr);
based on jm5kc
Output for 5.3.18 - 7.2.0
Array ( [14] => Array ( [x] => stdClass Object ( [num] => 1 ) [oele] => Array ( [0] => stdClass Object ( [num] => 1 ) [1] => stdClass Object ( [num] => 2 ) [2] => stdClass Object ( [num] => 3 ) [3] => stdClass Object ( [num] => 4 ) ) [boele] => Array ( [one] => 4 [two] => 10 ) ) [91] => Array ( [x] => stdClass Object ( [num] => 1 ) [oele] => Array ( [0] => stdClass Object ( [num] => 9 ) [1] => stdClass Object ( [num] => 8 ) [2] => stdClass Object ( [num] => 7 ) [3] => stdClass Object ( [num] => 6 ) ) [boele] => Array ( [one] => 4 [two] => 30 ) ) )