Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Array
(
[0] => Array
(
[0] => 2017-03-05 00:00:39
[1] => ABCD
[2] => 1234
)
[1] => Array
(
[0] => 2017-03-05 00:00:39
[1] => EFGH
[2] => 42342
)
[2] => Array
(
[0] => 2017-03-07 00:00:39
[1] => ABCD
[2] => 331242493
)
[3] => Array
(
[0] => 2017-03-07 00:00:39
[1] => EFGH
[2] => 46656
)
[4] => Array
(
[0] => 2017-03-06 00:00:39
[1] => ABCD
[2] => 7676
)
[5] => Array
(
[0] => 2017-03-06 00:00:39
[1] => EFGH
[2] => 98989
)
)
I need to get all the values that has 1st index as 'ABCD' in an array and sort the result based on the datetime (0th index).
My output should be this value :
[0] => Array
(
[0] => 2017-03-07 00:00:39
[1] => ABCD
[2] => 331242493
)
Please help.
Thanks in advance

What I have tried:

$array=array();
for($polIndex=0;$polIndex < count($pol_array);$polIndex++)//loop for getting items from pol item
{
$array = preg_grep("ABCD", $pol_array, PREG_GREP_INVERT);
}
Posted
Updated 6-Mar-17 0:23am

1 solution

  • Create a new array containing just the items that satisfy the required condition (i.e. index 1 having value 'ABCD').
  • Sort the newly created array by datetime (see, for instance here[^]).
 
Share this answer
 
Comments
User1454 6-Mar-17 10:32am    
Hi thanks for the reply. For the first point, is it possible only through looping? Because there are many items in that array.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900