简体   繁体   中英

Get index of element in array and search for it in another array

I want to get the index of an element which I'm looking for using in_array("Tuesday", $day) and get the element from another array on the same position as this one. I have 2 arrays: $day and $action . I need some help with this, I'm stuck.

the in_array won't return you any index, it's just a boolean, array_search does the same job and returns the key, ex:

$key = array_search("Tuesday", $day); 
if($key !== false)
   // do stuff (and you can of course do $action[$key]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM