3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array1 = ["name1","name2","name3","name4"]; $array2 = ["name2","name1","name3","name4"]; $arr = ["-1" => "down", "0" => "same", "1" => "up"]; $result = []; foreach(array_unique($array1) as $k => $v){ $result[$v] = $arr[array_search($v, $array2) <=> $k]; } print_r($result);
based on QXYc8
Output for 7.0.0 - 7.2.0
Array ( [name1] => up [name2] => down [name3] => same [name4] => same )
Output for 5.4.2 - 5.6.28
Parse error: syntax error, unexpected '>' in /in/5fpN8 on line 9
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/5fpN8 on line 3
Process exited with code 255.