Multi-Dimensional PHP Array Search


24 Aug 15 - 12:09

Hi Guys

I’m busy with a really cool PHP project. I thought today, I would share a multi-dimensional search function that you can use in PHP.

###Multi-Dimensional PHP Array Search

/*

    $find = What you're searching for
    $array = The array you want to search in
    $inField = The field in the array in which you will find $find

*/
function searchInArray($find, $array, $inField) {
   foreach ($array as $key => $value) {
       if ($value[$inField] === $find) {
           return TRUE;
       }
   }
   return FALSE;
}

That is an adaptation of the script outlined by Jakub Truneček here

-kyluke



Archives