@ 2015-09-20T08:03:40Z <?php
function modify_in_place($prices) {
$prices[0] = 100;
}
function modify_location($prices) {
$prices = [40, 50, 60];
}
$prices = [1, 2, 3];
modify_in_place($prices);
if ($prices[0] == 100) {
echo "Pass-by-reference!";
} else {
echo "Pass-by-value!";
}
$prices = [1, 2, 3];
modify_location($prices);
assert($prices[0] == 40); //failed! pass-by-value
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Pass-by-value!
Fatal error: Uncaught AssertionError: assert($prices[0] == 40) in /in/fW2T3:23
Stack trace:
#0 /in/fW2T3(23): assert(false, 'assert($prices[...')
#1 {main}
thrown in /in/fW2T3 on line 23
Process exited with code 255 . Output for 7.0.0 - 7.0.20 , 7.1.0 - 7.1.25 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 Pass-by-value!
Warning: assert(): assert($prices[0] == 40) failed in /in/fW2T3 on line 23
Output for 5.4.2 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.7 - 5.6.28 Pass-by-value!
Warning: assert(): Assertion failed in /in/fW2T3 on line 23
preferences:dark mode live preview
193.25 ms | 402 KiB | 242 Q