<?php
function transformQuestionnaire($arr) {
$new_arr = array();
foreach ($arr as $nr => $array){
if (!in_array($array[0], $new_arr)){ //not a double
$new_arr[$array[0]] = $array[1];
} else { //Append it to the existing value
$new_arr[$array[0]] = $new_arr[$array[0]] . '|' . $array[1];
}
}
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.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.28, 5.4.0 - 5.4.29
- Parse error: syntax error, unexpected ';' in /in/eFEpr on line 20
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, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected ';' in /in/eFEpr on line 20
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/eFEpr on line 20
Process exited with code 255.
preferences:
227.31 ms | 1395 KiB | 119 Q