02 May, 2010

Check If A Value Exists In Multidimensional Array

Here is a function which will help you to know if a value exists in Multidimensional Array.

  1. function in_mdarray($needle,$array)
  2. {
  3.     if (array_key_exists($needle,$array) or in_array($needle,$array))
  4.     {
  5.          return true;
  6.     }
  7.     else
  8.     {
  9.           $return = false;
  10.           foreach (array_values($array) as $value)
  11.           {
  12.               if (is_array($value) and !$return)
  13.               {
  14.                   $return = in_mdarray($needle,$value);
  15.               }
  16.           }
  17.           return $return;
  18.     }
  19. }

1 comment:

  1. Hi Eshan,

    Could you please contact me at james@affilipoint.com regarding a PHP Job based on CodeIgniter.

    Many thanks

    Regards
    James

    ReplyDelete