I have the following array
01 03 02 15
05 04 06 10
07 09 08 11
12 14 13 16
I want to convert a string like the following:
Looking at the solutions proposed so far, only one actually generates the correct output requested by the OP.
So, stealing unashamedly from salathe's neat conversion, but with a transpose to provide the correct result:
$input = array (
array ('01','03','02','15'),
array ('05','04','06','10'),
array ('07','09','08','11'),
array ('12','14','13','16'),
);
function transpose($array) {
array_unshift($array, null);
return call_user_func_array('array_map', $array);
}
$transposed = transpose($input);
echo implode('|', array_map('implode', $transposed, array_fill(0, count($transposed), ',')));