php - Using equal values within 2 arrays to display values from third array -


i have 2 arrays want compare, , collect similar values use in order display values third array.
array 1:

$global_days = array("monday", "thursday", "friday", "sunday"); 

array 2:

$global_day = array("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"); 

array 3:

$global_dates = array("11-05-2015", "12-05-2015", "13-05-2015", "14-05-2015", "15-05-2015", "16-05-2015", "17-05-2015"); 

so want display date equal days shown in first array, example show:

11-05-2015 14-05-2015 15-05-2015 17-05-2015 

from have seen, array_intersect() looking for, examples have seen of confusing.
data shown here bit different intend use, functionality need, giving alternatives getting date won't help

things note. when intersecting need pay attention first array, 1 compared against. array_intersect provides of values in $global_day @ indices mapped $global_dates. can map result of intersection with $global_dates retrieve mapped values comparing keys retrieved first intersection.

this should achieve goal

$global_days = array("monday", "thursday", "friday", "sunday"); $global_day = array("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"); $global_dates = array("11-05-2015", "12-05-2015", "13-05-2015", "14-05-2015", "15-05-2015", "16-05-2015", "17-05-2015");  $keys = array_intersect($global_day, $global_days); $result = array_intersect_key($global_dates, $keys); 

try out: http://www.tehplayground.com/#zkyzv0dwh


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -