3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $strings = "Football / Germany / 1.Liga Football / Germany / 1.Liga Football / Germany / 2.Liga Football / Germany / 2.Liga Football / Germany / 2.Liga Football / England / 1.Liga Football / England / 1.Liga Football / England / 2.Liga Football / England / 2.Liga Football / England / 3.Liga Hockey / Germany / 1.Liga Hockey / Germany / 1.Liga Hockey / Germany / 2.Liga Fechten / Meisterschaft Fechten / Meisterschaft Fechten / Weltmeister"; $lines = explode("\n", $strings); $array = array(); foreach($lines as $line) { $values = explode(' / ', $line); $depth = 0; foreach($values as $value) { if(!in_array($value, $array[$depth])) $array[$depth][] = $value; $depth++; } } var_dump($array);
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined offset: 0 in /in/eseQK on line 27 Warning: in_array() expects parameter 2 to be array, null given in /in/eseQK on line 27 Notice: Undefined offset: 1 in /in/eseQK on line 27 Warning: in_array() expects parameter 2 to be array, null given in /in/eseQK on line 27 Notice: Undefined offset: 2 in /in/eseQK on line 27 Warning: in_array() expects parameter 2 to be array, null given in /in/eseQK on line 27 array(3) { [0]=> array(3) { [0]=> string(8) "Football" [1]=> string(6) "Hockey" [2]=> string(7) "Fechten" } [1]=> array(4) { [0]=> string(7) "Germany" [1]=> string(7) "England" [2]=> string(13) "Meisterschaft" [3]=> string(11) "Weltmeister" } [2]=> array(3) { [0]=> string(6) "1.Liga" [1]=> string(6) "2.Liga" [2]=> string(6) "3.Liga" } }
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined index: 0 in /in/eseQK on line 27 Warning: in_array() expects parameter 2 to be an array or collection in /in/eseQK on line 27 Notice: Undefined index: 1 in /in/eseQK on line 27 Warning: in_array() expects parameter 2 to be an array or collection in /in/eseQK on line 27 Notice: Undefined index: 2 in /in/eseQK on line 27 Warning: in_array() expects parameter 2 to be an array or collection in /in/eseQK on line 27 array(3) { [0]=> array(3) { [0]=> string(8) "Football" [1]=> string(6) "Hockey" [2]=> string(7) "Fechten" } [1]=> array(4) { [0]=> string(7) "Germany" [1]=> string(7) "England" [2]=> string(13) "Meisterschaft" [3]=> string(11) "Weltmeister" } [2]=> array(3) { [0]=> string(6) "1.Liga" [1]=> string(6) "2.Liga" [2]=> string(6) "3.Liga" } }
Output for 4.3.2 - 5.2.17
Notice: Undefined offset: 0 in /in/eseQK on line 27 Warning: in_array(): Wrong datatype for second argument in /in/eseQK on line 27 Notice: Undefined offset: 1 in /in/eseQK on line 27 Warning: in_array(): Wrong datatype for second argument in /in/eseQK on line 27 Notice: Undefined offset: 2 in /in/eseQK on line 27 Warning: in_array(): Wrong datatype for second argument in /in/eseQK on line 27 array(3) { [0]=> array(3) { [0]=> string(8) "Football" [1]=> string(6) "Hockey" [2]=> string(7) "Fechten" } [1]=> array(4) { [0]=> string(7) "Germany" [1]=> string(7) "England" [2]=> string(13) "Meisterschaft" [3]=> string(11) "Weltmeister" } [2]=> array(3) { [0]=> string(6) "1.Liga" [1]=> string(6) "2.Liga" [2]=> string(6) "3.Liga" } }
Output for 4.3.0 - 4.3.1
Notice: Undefined offset: 0 in /in/eseQK on line 27 Warning: in_array() [http://www.php.net/function.in-array]: Wrong datatype for second argument in /in/eseQK on line 27 Notice: Undefined offset: 1 in /in/eseQK on line 27 Warning: in_array() [http://www.php.net/function.in-array]: Wrong datatype for second argument in /in/eseQK on line 27 Notice: Undefined offset: 2 in /in/eseQK on line 27 Warning: in_array() [http://www.php.net/function.in-array]: Wrong datatype for second argument in /in/eseQK on line 27 array(3) { [0]=> array(3) { [0]=> string(8) "Football" [1]=> string(6) "Hockey" [2]=> string(7) "Fechten" } [1]=> array(4) { [0]=> string(7) "Germany" [1]=> string(7) "England" [2]=> string(13) "Meisterschaft" [3]=> string(11) "Weltmeister" } [2]=> array(3) { [0]=> string(6) "1.Liga" [1]=> string(6) "2.Liga" [2]=> string(6) "3.Liga" } }