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.
1 Answer
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]
1 Comment
Jon
if ($key > 0) is wrong. Just read the documentation: if ($key !== false) is correct.
in_arraylike this:if(in_array("Tuesday, $day)){}. If it is in array, I want to take it's position in the array and print the element on the same position from the other array.$key = array_search("Tuesday, $day); if $key > 0 // do stuff (and you can of course do $action[$key]