Skip to content
Advertisement

Pattern Match on a Array Key

I need to get the stock values out of this array:

JavaScript

I need to pattern match on this array, where the array key = “stock” + 1 wildcard character. I have tried using the array filter function to get every other value on the PHP manual but the empty values seem to throw it out. I tried alot of different things I found but nothing is working.

Can this be done?

Advertisement

Answer

array_filter does not have access to the key and therefore is not the right tool for your job.

I belive what you’re looking to do is this:

JavaScript

Now $stockList looks like this:

JavaScript

You may need to fuss with it a bit, but I think this is what you are asking for.

HOWEVER, you really should be following Jeff Ober’s advice if you have the option to do so.

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