I have a simple, two dimensional array like this:
Array
(
[0] => Array
(
[0] => abc
[1] => 1
Anything wrong with just looping through it?
for ( $i = 0; $i < sizeof($input); $i++ ) {
for ( $j = 0; $j < $n; $j++ ) {
$output[$i][$j] = $input[$i][$j];
}
}
return $output;
Even with array_walk :
array_walk(
$aYourArray,
function(&$aSubRow){
$aSubRow = array_slice($aSubRow, 0, 2);
}
);
const MAX = 2; // maximum number of elements
foreach ($array as &$element) {
$element = array_slice($element, 0, MAX);
}
foreach($array as $key=> $element)
{
for($i=0; $i<$n; $i++)
{
$newArray[$key][$i] = $element[$i];
}
}
Not sure if there is a more efficient method.