<?php
static $cnt=0;
$name='victor';
$coll = array(
'dep1'=>array(
'fy'=>array('john','johnny','victor'),
'sy'=>array('david','arthur'),
'ty'=>array('sam','joe','victor')
),
'dep2'=>array(
'fy'=>array('natalie','linda','molly'),
'sy'=>array('katie','helen','sam','ravi','vipul'),
'ty'=>array('sharon','julia','maddy')
)
);
function array_find($name,$arr)
{
global $cnt;
if(!(is_array($arr)))
return false;
foreach($arr as $val)
{
if(is_array($val))
array_find($name,$val);
else
{
$val=strtolower($val);
$item=strtolower($name);
if($val==$name)
$cnt+=1;
}
}
}
array_find($name,$coll);
if($cnt==0)
echo "$name was Not Found";
else
echo "$name was found $cnt times.";
Take the 2-minute tour
×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
|
||||
show 8 more comments |
Try this code, hope it will work
|
|||||||||||||||||
|
victor was found 2 times.
isn't that right ? – Shankar Damodaran Mar 7 at 6:07