3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a = ["a", "\b", "c"]; foreach($a as $key => &$value) { echo "-------------------------------------------------------------\n"; echo "Original Array:\n"; echo "Input key: $key value: $value\n"; var_dump($a); if($value == "\b") { array_splice($a, $key, 1, ["b-bool", "b-int", "\d"]); echo "Modified Array:\n"; var_dump($a); } if($value == "\d") { array_splice($a, $key, 1, ["d-bool", "d-int"]); echo "Modified Array:\n"; var_dump($a); } // Otherwise the Final Array will have the last element in reference unset($value); } echo "-------------------------------------------------------------\n"; echo "Final Array:\n"; var_dump($a);
Output for 7.0.0 - 7.2.0
------------------------------------------------------------- Original Array: Input key: 0 value: a array(3) { [0]=> &string(1) "a" [1]=> string(2) "\b" [2]=> string(1) "c" } ------------------------------------------------------------- Original Array: Input key: 1 value: \b array(3) { [0]=> string(1) "a" [1]=> &string(2) "\b" [2]=> string(1) "c" } Modified Array: array(5) { [0]=> string(1) "a" [1]=> string(6) "b-bool" [2]=> string(5) "b-int" [3]=> string(2) "\d" [4]=> string(1) "c" } ------------------------------------------------------------- Original Array: Input key: 4 value: c array(5) { [0]=> string(1) "a" [1]=> string(6) "b-bool" [2]=> string(5) "b-int" [3]=> string(2) "\d" [4]=> &string(1) "c" } ------------------------------------------------------------- Final Array: array(5) { [0]=> string(1) "a" [1]=> string(6) "b-bool" [2]=> string(5) "b-int" [3]=> string(2) "\d" [4]=> string(1) "c" }
Output for 5.4.9 - 5.6.28
------------------------------------------------------------- Original Array: Input key: 0 value: a array(3) { [0]=> &string(1) "a" [1]=> string(2) "\b" [2]=> string(1) "c" } ------------------------------------------------------------- Original Array: Input key: 1 value: \b array(3) { [0]=> string(1) "a" [1]=> &string(2) "\b" [2]=> string(1) "c" } Modified Array: array(5) { [0]=> string(1) "a" [1]=> string(6) "b-bool" [2]=> string(5) "b-int" [3]=> string(2) "\d" [4]=> string(1) "c" } ------------------------------------------------------------- Original Array: Input key: 0 value: a array(5) { [0]=> &string(1) "a" [1]=> string(6) "b-bool" [2]=> string(5) "b-int" [3]=> string(2) "\d" [4]=> string(1) "c" } ------------------------------------------------------------- Original Array: Input key: 1 value: b-bool array(5) { [0]=> string(1) "a" [1]=> &string(6) "b-bool" [2]=> string(5) "b-int" [3]=> string(2) "\d" [4]=> string(1) "c" } ------------------------------------------------------------- Original Array: Input key: 2 value: b-int array(5) { [0]=> string(1) "a" [1]=> string(6) "b-bool" [2]=> &string(5) "b-int" [3]=> string(2) "\d" [4]=> string(1) "c" } ------------------------------------------------------------- Original Array: Input key: 3 value: \d array(5) { [0]=> string(1) "a" [1]=> string(6) "b-bool" [2]=> string(5) "b-int" [3]=> &string(2) "\d" [4]=> string(1) "c" } Modified Array: array(6) { [0]=> string(1) "a" [1]=> string(6) "b-bool" [2]=> string(5) "b-int" [3]=> string(6) "d-bool" [4]=> string(5) "d-int" [5]=> string(1) "c" } ------------------------------------------------------------- Original Array: Input key: 0 value: a array(6) { [0]=> &string(1) "a" [1]=> string(6) "b-bool" [2]=> string(5) "b-int" [3]=> string(6) "d-bool" [4]=> string(5) "d-int" [5]=> string(1) "c" } ------------------------------------------------------------- Original Array: Input key: 1 value: b-bool array(6) { [0]=> string(1) "a" [1]=> &string(6) "b-bool" [2]=> string(5) "b-int" [3]=> string(6) "d-bool" [4]=> string(5) "d-int" [5]=> string(1) "c" } ------------------------------------------------------------- Original Array: Input key: 2 value: b-int array(6) { [0]=> string(1) "a" [1]=> string(6) "b-bool" [2]=> &string(5) "b-int" [3]=> string(6) "d-bool" [4]=> string(5) "d-int" [5]=> string(1) "c" } ------------------------------------------------------------- Original Array: Input key: 3 value: d-bool array(6) { [0]=> string(1) "a" [1]=> string(6) "b-bool" [2]=> string(5) "b-int" [3]=> &string(6) "d-bool" [4]=> string(5) "d-int" [5]=> string(1) "c" } ------------------------------------------------------------- Original Array: Input key: 4 value: d-int array(6) { [0]=> string(1) "a" [1]=> string(6) "b-bool" [2]=> string(5) "b-int" [3]=> string(6) "d-bool" [4]=> &string(5) "d-int" [5]=> string(1) "c" } ------------------------------------------------------------- Original Array: Input key: 5 value: c array(6) { [0]=> string(1) "a" [1]=> string(6) "b-bool" [2]=> string(5) "b-int" [3]=> string(6) "d-bool" [4]=> string(5) "d-int" [5]=> &string(1) "c" } ------------------------------------------------------------- Final Array: array(6) { [0]=> string(1) "a" [1]=> string(6) "b-bool" [2]=> string(5) "b-int" [3]=> string(6) "d-bool" [4]=> string(5) "d-int" [5]=> string(1) "c" }
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/OdcoI on line 3
Process exited with code 255.