Just wondering if anyone has transformed a 2 dim array to a one dim array in php. I\'ve yet to come across a clear explanation in php. Any suggestion would be appreciated.
It depends on what you need but if you want to reduce your 2d array to a 1d curve that completley fills the 2d plane you probably looking for a spatial index or a space-filling-curve. There are some famous and not so known like the z-curve, the hilbert curve, the peano curve or the moore curve. You can write such a curve with a L-system.
Try this:
function array_2d_to_1d ($input_array) {
$output_array = array();
for ($i = 0; $i < count($input_array); $i++) {
for ($j = 0; $j < count($input_array[$i]); $j++) {
$output_array[] = $input_array[$i][$j];
}
}
return $output_array;
}