Skip to content
Advertisement

How to get the values only if all the keys have matched?

I want to make a method that returns keys and values. But only if the keys include the following string “_1” and “__last“. If only one matches then exit the function, only if the two string are included in the key, return the key with the value for a weather.

JavaScript

Advertisement

Answer

You are making your life so much more difficult that it need be, use str_contains() its easier than building complex REGEX’s and getting very confused by the look of it 🙂

I also fixed a number of other mistakes, such as the foreach that was not going to work, so check all the code. It is also better to pass data to a function/method otherwise you get into scoping issues!

JavaScript

RESULTS

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