php - Return array key by value given (month given to return a date) -


i have php multidimensional array key , array under has dates.

array (     [123] => array     (        [one] => 2016-01-22 10:32:15        [two] => 2016-02-21 14:24:15        [three] => 2016-02-12 11:00:15     )      [553] => array     (        [one] => 2016-03-22 10:32:15        [two] => 2016-02-21 14:24:15        [three] => 2016-08-12 11:00:15     )  ) 

i need key month given. example:

$value = '2016-02';  return 123 -> 2 return 552 -> 1 

how best approach achieve this? thank you.

you can below in simple way:-

<?php  $array = array (     '123' => array     (        'one' => '2016-01-22 10:32:15',        'two' => '2016-02-21 14:24:15',        'three' => '2016-02-12 11:00:15'     ),     '553' => array     (        'one' => '2016-03-22 10:32:15',        'two' => '2016-02-21 14:24:15',        'three' => '2016-08-12 11:00:15'     ) );  $value = '2016-02'; $final_data = array(); foreach ($array $key=> $arr){   foreach($arr $key1=>$val){     if(strpos($val,$value)!==false){        $final_data[$key][]=$key1;     }   } }  echo "<pre/>";print_r($final_data); 

output:-https://eval.in/627935

or 1 useful:-

https://eval.in/627936


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -