I have this array in PHP 5.2.3 :
$a = array (
array("a","c","1");
array("b","a","2");
array("a","b","3");
array("b","b","4");
array("a","a","5");
);
and I would like to "select" (or create a new array) only the rows that have the first element "a". Like this :
"a","c","1"
"a","b","3"
"a","a","5"
How can I do this ?
EDIT :
<?php
$a = array (
array("a","c","1"),
array("b","a","2"),
array("a","b","3"),
array("b","b","4"),
array("a","a","5"),
);
$result = array_filter(
$array,
'testFirst'
);
print_r($result);
?>
I get this error Warning: array_filter() [function.array-filter]: The first argument should be an array in C:\wamp\www\keySearch\test.php on line 13
FINAL EDIT :
<?php
$a = array (
array("a","c","1"),
array("b","a","2"),
array("a","b","3"),
array("b","b","4"),
array("a","a","5"),
);
function testFirst($value) {
return($value[0] == 'a');
}
$result = array_filter($a, testFirst);
print_r($result);
?>