如何基于PHP中的值对数组进行排序 [英] How to sort an array based on value in PHP

查看:76
本文介绍了如何基于PHP中的值对数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



数组



[0] =>数组



[0] => 2017-03-05 00:00:39

[1] => ABCD

[2] => 1234



[1] =>数组



[0] => 2017- 03-05 00:00:39

[1] => EFGH

[2] => 42342



[2] =>数组



[0] => 2017-03-07 00:00:39

[1] => ABCD

[2] => 331242493



[3] =>数组< br $> b $ b(

[0] => 2017-03-07 00:00:39

[1] => EFGH

[2] => 46656



[4] =>数组



[0] => 2017-03-06 00:00:39

[1] => ABCD

[2] => 7676



[5] =>数组



[0] => 2017-03-06 00:00:39

[1] => EFGH

[2] => 98989





我需要获得所有的值在数组中索引为'ABCD'并根据日期时间(第0个索引)对结果进行排序。

我的输出应为此值:

[0] =>数组



[0] => 2017-03-07 00:00:39

[1] => ABCD

[2] => 331242493



请帮忙。

提前致谢



我尝试过:



$ array = array();

for($ polIndex = 0; $ polIndex< count($ pol_array); $ polIndex ++)//循环从pol项目获取物品

{

$ array = preg_grep(ABCD,$ pol_array,PREG_GREP_INVERT);

}

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);
}

推荐答案

array = array();

for(
array=array();
for(


polIndex = 0;
polIndex=0;


polIndex< count(
polIndex < count(


这篇关于如何基于PHP中的值对数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆