Skip to content
Advertisement

Check if value exists with array_search()

I have an array called $resultstatsmatch with the folowing output:

JavaScript

Now I want to check if the array key [bonusidbonusstat0] contains the value “40”. If yes, it should appear a text.

Therefore I´m using the array_search() method but for some reason it doesn´t work, the text is shown, no matter the value exists or not.

This is the code:

JavaScript

Advertisement

Answer

Instead of using the array_search, I would recommend to use in_array() to check if bonusStat2 exist in the result of array_column

JavaScript

Try it online!

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement