获取数组中元素的索引并在另一个数组中搜索它

时间:2021-05-26 20:05:42

I want to get the index of an element wich 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.

我想使用in_array(“星期二”,$ day)获取我正在寻找的元素的索引,并从与此位置相同的位置获取另一个数组中的元素。我有2个数组:$ day和$ action。我需要一些帮助,我被困住了。

1 个解决方案

#1


1  

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:

in_array不会返回任何索引,它只是一个布尔值,array_search执行相同的工作并返回键,例如:

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

#1


1  

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:

in_array不会返回任何索引,它只是一个布尔值,array_search执行相同的工作并返回键,例如:

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