I’d like to check if there is a value on an array like this: I’ve read the check_value_new method is a better way to work with arrays, but I’m not used to work with it, how I should fix it? Answer PHP offers a function called in_array that checks if a value exists in a given array. You can change
Tag: foreach
PHP How to determine the first and last iteration in a foreach loop?
The question is simple. I have a foreach loop in my code: In this loop, I want to react differently when we are in first or last iteration. How to do this? Answer You could use a counter:
How to find the foreach index?
Is it possible to find the foreach index? in a for loop as follows: $i will give you the index. Do I have to use the for loop or is there some way to get the index in the foreach loop? Answer $key is the index of each $array element