Check Element in a Multidimensional Array in PHP

by Sasikumar 2014-06-06 22:11:51

To check whether a element is present in a multidimensional array, use the following php function
PHP Function:
function check_in_multidimensional_array($findVariable, $dataArray, $strictCheck = true) 
{
    foreach ($dataArray as $individualData)
    {
        if (($strictCheck ? $individualData=== $findVariable: $individualData== $findVariable) || (is_array($individualData) && check_in_multidimensional_array($findVariable, $individualData, $strictCheck ))) 
        {
            return true;
        }
    }
    return false;
}
Example:
$sites= array(array("hiox", "hscripts", "eluthu"), array("quotespick", "hibihi"), array("hioxindia", "jqslider","easycalculation"));

echo check_in_multidimensional_array("hscripts", $sites) ? 'Your Search Found' : 'Your Search Not found';
957
like
0
dislike
0
mail
flag

You must LOGIN to add comments