3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function transformQuestionnaire($arr) { $new_arr = array(); foreach ($arr as $array){ $key = reset($array); $val = end($array); if (!in_array($key, $new_arr)){ //not a double $new_arr[$key] = $val; } else { //Append it to the existing value $new_arr[$key] = $new_arr[$key] . '|' . $val; } } return $new_arr; } $input = array( 1 => array("one", "potato"), 2 => array("two", "fries"), 3 => array("one", "ketchup"), ); print(var_dump(transformQuestionnaire($input))); ?>
Output for 4.3.0 - 7.1.0
array(2) { ["one"]=> string(7) "ketchup" ["two"]=> string(5) "fries" }