3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rates = array( 'apple' => array( 'red' => array( 'rate' => 1.19, 'resume' => 'This is a red apple.' ), 'green' => array( 'rate' => 0.99, 'resume' => 'This is a green apple.' ), 'yellow' => array( 'rate' => 0.89, 'resume' => 'This is a yellow apple.' ), ) ); $cart = array( 'apple' => array( '0' => red, '1' => green ) ); $total = 0; foreach ($cart as $key => $arr) { if (isset($rates[$key])) { foreach ($arr as $value) { $total += $rates[$key]['rate'][$value] ?? 0; } } } echo $total;
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
Fatal error: Uncaught Error: Undefined constant "red" in /in/vsEvA:22 Stack trace: #0 {main} thrown in /in/vsEvA on line 22
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: Use of undefined constant red - assumed 'red' (this will throw an Error in a future version of PHP) in /in/vsEvA on line 22 Warning: Use of undefined constant green - assumed 'green' (this will throw an Error in a future version of PHP) in /in/vsEvA on line 23 0

preferences:
155.98 ms | 408 KiB | 5 Q