Check Element in a Multidimensional Array in PHP
by Sasikumar[ Edit ] 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';