I have two arrays in php named as company_timings
and in_time
, respectively.
I have found the common elements in both the arrays and stored those common elements in common array.
Now I want to find the indexes of these common elements in the first array, i.e in company_timing
.
Below is my code:
$length_of_company=sizeof($company_timings);
$length_of_emp=sizeof($in_time);
for ($i=0; $i <=$length_of_company-1; $i++) {
# code...
for ($j=0; $j<=$length_of_emp-1; $j++) {
# code...
if ($in_time[$j]==$company_timings[$i]) {
# code...
$common[]=$company_timings[$i];
}
}
}
All the three arrays look like these
$company_timings=array('09:00:00','10:00:00'.'11:00:00','12:00:00');
$in_time=array('09:00:00','11:00:00');
$common=array('09:00:00','11:00:00');
Now I tried passing $common
in array_search
func to find the indexes of 09:00:00 and 11:00:00 respectively in $company_timings
$indexes=array_search($common,$company_timings);
but I didn't get anything but when I used
$indexes=array_search("11:00:00",$company_timings);
I got the desired outcome which is 12...
Can you guys tell me how should I achieve that?