Björn C
Björn C

Reputation: 4008

Find values from date in array

So i have been reading about array_search, array_values & array_keys but i cannot figure out how to search my array and put founded values in a new array.

I have allYearData array.
It looks likt this:

Array ( [0] => Array ( [id] => 7811 [objekt_element] => 23050-121-1_3105 [objekt_nr] => 23050-121-1 [element_nr] => 3105 [vart] => B.Avf [vem] => Blå [anteckn] => [datum] => 2015-01-29 18:00:19 )

Now i´d like to split this array in part by dates.
so, search in the "key" "datum" and find all "values" ecual to: "2015-01-%"
Put it in array: "janData".

So i tried this:

$janElementCount = array_search("2015-01-%", $allYearData);
print_r($janElementCount);

This won´t get me anything at all. How come?

Upvotes: 0

Views: 43

Answers (1)

Manwal
Manwal

Reputation: 23816

array_search() match exact value you are looking for PHP preg_grep()

$janElementCount = preg_grep("/^2015-01-.*$/", $allYearData[0]);

Note: Because your array is at [0] position so pass $allYearData[0].

See working DEMO

Upvotes: 1

Related Questions