Is there a better way to do a search within an array of associative arrays? :)
Basically a way to replace the function that I did that works, but was wondering if there's a better way.
<?php
$employee = array();
$employee [] = array("name" =>"Chris Apple", "company" => "Acme inc.", "title" => "Developer", "salary" => "77000");
$employee [] = array("name" =>"Todd Orange", "company" => "Daves Dogs", "title" => "Mgr", "salary" => "177000");
$employee [] = array("name" =>"Gordon Banana", "company" => "Acme inc.", "title" => "Mgr", "salary" => "277000");
$employee [] = array("name" =>"Kim Pear", "company" => "XYZ Signs", "title" => "sales", "salary" => "77000");
$employee [] = array("name" =>"Steve Cherry", "company" => "self", "title" => "handyman", "salary" => "27000");
$employee [] = array("name" =>"Jay Pineapple", "company" => "Acme inc.", "title" => "sales", "salary" => "47000");
$filtered = filter_array($employee, 'company', 'Acme inc.');
echo "<pre>";
echo "original array<br>".print_r($employee,true)."<br>";
echo "new array<br>".print_r($filtered,true)."<br>";
echo "</pre>";
//hack unless a better way is possible
function filter_array($hackstack, $fieldname, $needle)
{
$newarray = array();
foreach($hackstack as $key=>$subarray)
{
if($subarray[$fieldname]==$needle)
{
$newarray[] = $subarray;
}
}
return($newarray);
}