php - Pattern Match on a Array Key -


I need to get stock prices from this array:

  Array ([stock0 ] = & Gt; [[Stock 1] => [Stock 1] => 3 [StockDate 1] => Apple [Stock 2] => 2 [StockDate 2] = & gt;)  

I need pattern matching on this array, where array key = "stock" + 1 wildcard character I have tried using the array filter function to get every second value on PHP manual, but the empty values ​​start throwing it down. I tried many things which I found but nothing is working.

Can this be done?

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

I believe this is what you want to do:

  $ share = array ("stock 0" => 1, "stockdate" = & gt; ; '', 'Stock 1' = & gt; 3, 'stockdate1' = & gt; 'apple' '' stock2 '=> 2,' stockdate 2 '=>); $ StockList = array (); // "stock" indexed by the number found at the end of foreign currency ($ share = $ share = as of $> $ stock) {sscanf ($ stockKey, "stock% d" and stock IDID) " Your list of "stock"; // Scan into a formatted string and reference the values ​​passed by the reference values ​​($ stockId! == incorrect) $ share list [$ stockId] = $ stock;  

Now the $ sharelist looks like this:

  array ([0] => 1 [1] => 3 [2] = & Gt; 2)  

You may have to do something wrong with it, but I think this is what you are asking for.

But, if you really like Jeff Ober's advice, you have the option to do this.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -