Skip to content
Advertisement

Tag: foreach

Check if an array contains a specific value?

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

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

Advertisement