array_filter does not have access to the key and therefore is not suitable for your work.
I believe you want to do this:
$stocks = Array ( "stock0" => 1, "stockdate0" => '', "stock1" => 3, "stockdate1" => 'apple', "stock2" => 2, "stockdate2" => '' ); $stockList = array(); //Your list of "stocks" indexed by the number found at the end of "stock" foreach ($stocks as $stockKey => $stock) { sscanf($stockKey,"stock%d", &stockId); // scan into a formatted string and return values passed by reference if ($stockId !== false) $stockList[$stockId] = $stock; }
Now $ stockList looks like this:
Array ( [0] => 1 [1] => 3 [2] => 2 )
You may need a little with him, but I think this is what you are asking for.
HOWEVER, you really should follow Jeff Obron's advice, if you have the opportunity to do so.
Chronofish
source share