3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getMeat($foods) { if (!isset($foods['meats'])) { throw new Exception('There is no meat in this pie'); } $meatCount = count($foods['meats']); if($meatCount < 1) { throw new Exception('Where did all the meat go!?'); } var_dump($foods); $i = 0; $j = 1; while($i < $meatCount) { if ($foods['meats'][$i] < $foods['meats'][$j]) { $tempMeat = $foods['meats'][$i]; $foods['meats'][$i] = $foods['meats'][$j]; $foods['meats'][$j] = $tempMeat; } $i++; $j++; } var_dump($foods); } $foods = array( 'meats' => array('burgers', 'steak', 'sausages', 'kebabs'), 'cake' => array('victorian', 'chocolate', 'fruit', 'fudge'), ); getMeat($foods);
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
array(2) { ["meats"]=> array(4) { [0]=> string(7) "burgers" [1]=> string(5) "steak" [2]=> string(8) "sausages" [3]=> string(6) "kebabs" } ["cake"]=> array(4) { [0]=> string(9) "victorian" [1]=> string(9) "chocolate" [2]=> string(5) "fruit" [3]=> string(5) "fudge" } } Warning: Undefined array key 4 in /in/tVlBa on line 23 array(2) { ["meats"]=> array(4) { [0]=> string(5) "steak" [1]=> string(8) "sausages" [2]=> string(6) "kebabs" [3]=> string(7) "burgers" } ["cake"]=> array(4) { [0]=> string(9) "victorian" [1]=> string(9) "chocolate" [2]=> string(5) "fruit" [3]=> string(5) "fudge" } }
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.12 - 7.3.31, 7.4.0 - 7.4.33
array(2) { ["meats"]=> array(4) { [0]=> string(7) "burgers" [1]=> string(5) "steak" [2]=> string(8) "sausages" [3]=> string(6) "kebabs" } ["cake"]=> array(4) { [0]=> string(9) "victorian" [1]=> string(9) "chocolate" [2]=> string(5) "fruit" [3]=> string(5) "fudge" } } Notice: Undefined offset: 4 in /in/tVlBa on line 23 array(2) { ["meats"]=> array(4) { [0]=> string(5) "steak" [1]=> string(8) "sausages" [2]=> string(6) "kebabs" [3]=> string(7) "burgers" } ["cake"]=> array(4) { [0]=> string(9) "victorian" [1]=> string(9) "chocolate" [2]=> string(5) "fruit" [3]=> string(5) "fudge" } }
Output for 7.3.32 - 7.3.33
array(2) { ["meats"]=> array(4) { [0]=> string(7) "burgers" [1]=> string(5) "steak" [2]=> string(8) "sausages" [3]=> string(6) "kebabs" } ["cake"]=> array(4) { [0]=> string(9) "victorian" [1]=> string(9) "chocolate" [2]=> string(5) "fruit" [3]=> string(5) "fudge" } } array(2) { ["meats"]=> array(4) { [0]=> string(5) "steak" [1]=> string(8) "sausages" [2]=> string(6) "kebabs" [3]=> string(7) "burgers" } ["cake"]=> array(4) { [0]=> string(9) "victorian" [1]=> string(9) "chocolate" [2]=> string(5) "fruit" [3]=> string(5) "fudge" } }
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
array(2) { ["meats"]=> array(4) { [0]=> string(7) "burgers" [1]=> string(5) "steak" [2]=> string(8) "sausages" [3]=> string(6) "kebabs" } ["cake"]=> array(4) { [0]=> string(9) "victorian" [1]=> string(9) "chocolate" [2]=> string(5) "fruit" [3]=> string(5) "fudge" } } Notice: Undefined offset: 4 in /in/tVlBa on line 23 array(2) { ["meats"]=> array(4) { [0]=> string(5) "steak" [1]=> string(8) "sausages" [2]=> string(6) "kebabs" [3]=> string(7) "burgers" } ["cake"]=> array(4) { [0]=> string(9) "victorian" [1]=> string(9) "chocolate" [2]=> string(5) "fruit" [3]=> string(5) "fudge" } }
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_NEW in /in/tVlBa on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_NEW in /in/tVlBa on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/tVlBa on line 7
Process exited with code 255.

preferences:
229.66 ms | 401 KiB | 354 Q