How can I filter out certain items in an array using php?
I would like to filter out a php array based on some search criteria, but
it's not quite working.
I've been trying this code I found on google, but it giving an error?
$shortWords = '/'.$_GET['sSearch'].'/i';
$rResult = array_filter($rResult,
function($x) use ($shortWords) {
return preg_match($shortWords,$x);
});
Here is the error:
preg_match() expects parameter 2 to be string, array given
I don't quite know what the "function($x) use...." is doing...my
limitations to php.
Here is what the array looks like before the "array_filter()":
array(
[0] =>
array(
['unit_nbr'] =>'BBC 2'
['p_unit_group_id'] =>NULL
['name'] =>1
['unit_id'] =>22640
['properties_id'] =>1450
)
[1] =>
array(
['unit_nbr'] =>'BBC 3'
['p_unit_group_id'] =>NULL
['name'] =>1
['unit_id'] =>22641
['properties_id'] =>1450
)
I would like to have the unit_nbr "BBC 2" remain in the array when I pass
that search string over to the function. I don't know what I'm doing
wrong.
Any help is appreciated.
Thanks in advance.
No comments:
Post a Comment