我有一个PHP数组,如下所示:
Array{
[0] {
'id' => '0',
'title' => 'foo',
'address' => '123 Somewhere',
}
[1] {
'id' => '1',
'title' => 'bar',
'address' => '123 Nowhere',
}
[2] {
'id' => '2',
'title' => 'barfoo',
'address' => '123 Elsewhere',
}
[3] {
'id' => '3',
'title' => 'foobar',
'address' => '123 Whereabouts',
}
}
Run Code Online (Sandbox Code Playgroud)
我想通过嵌套数组中的'title'键对其进行排序,如下所示:
Array{
[1] {
'id' => '1',
'title' => 'bar',
'address' => '123 Nowhere',
}
[2] {
'id' => '2',
'title' => 'barfoo',
'address' => …Run Code Online (Sandbox Code Playgroud) 我的阵列:
$MY_ARRAY =
Array
(
[0] => Array
(
[0] => 2861
[1] => Array
(
[start_month] => 6
[start_year] => 1970
[end_month] => 12
[end_year] => 1990
[experience_info] => "Practically a random string"
)
)
)
Run Code Online (Sandbox Code Playgroud)
我希望$MY_ARRAY通过内部内容对直接孩子进行排序,理想情况是以start_year,start_month,end_year,end_month的顺序排列.我想我可以用array_multisort()某种方式,但我不知道如何.有谁知道如何处理这个?
谢谢.
编辑:当它出现时,解决方案很简单,我不知道的是,在回调比较函数的比较中你可以进入更深层次的结构 - 所以如果你的lvl-1索引比你的更深层保持不变(我的情况)那是怎么做的:)
我需要按照getNotifications函数中值'start_date'的DESC顺序对通知数组进行排序:
$posts_id_arr = getPoststIds($conn);
foreach ($posts_id_arr as $key => $val) {
$total_arr[$key] = [
'notification' => getNotifications($val['post_id'], $user_id, $conn)
];
}
$response_array = array('data' => $total_arr, 'more things' => $more_array);
echo json_encode($response_array);
Run Code Online (Sandbox Code Playgroud)
现在,由于foreach循环,订单是通过邮递ID进行的。
data {
notification:
[
{
post_id: “1",
start_date: "2016-10-10 08:00:00",
},
{
post_id: “1",
start_date: "2016-10-10 12:00:00",
}
],
notification:
[
post_id: “2",
start_date: "2016-10-10 09:00:00",
},
{
post_id: “2",
start_date: "2016-10-10 13:00:00",
}
]
}
Run Code Online (Sandbox Code Playgroud)
我需要是1:08:00,2:09:00,1:12:00,2:13:00
我有一个数组,需要使用键值"odbyx"进行排序
这是数组var_dump
array(12) {
["id"]=> array(7) {
[0]=> string(1) "8"
[1]=> string(1) "7"
[2]=> string(1) "3"
[3]=> string(1) "6"
[4]=> string(1) "5"
[5]=> string(1) "2"
[6]=> string(1) "1"
}
["subject"]=> array(7) {
[0]=> string(14) "ticke tick sbj"
[1]=> string(13) "new tick test"
[2]=> string(15) "fdsfdsfdsfdsfds"
[3]=> string(12) "test subject"
[4]=> string(4) "test"
[5]=> string(4) "test"
[6]=> string(12) "test subject"
}
["msg"]=> array(7) {
[0]=> string(9) "test+tick"
[1]=> string(4) "test"
[2]=> string(9) "dfdsfdsfd"
[3]=> string(12) "test+tcikets"
[4]=> string(4) "test"
[5]=> …Run Code Online (Sandbox Code Playgroud) 我在 PHP 中有这个数组:
在 PHP API 中,我有这个数组,想按 custom_price 排序,但不知道如何实现..
Array
(
[0] => Array
(
[id] => 1204
[custom_price] => 33.1500
)
[1] => Array
(
[id] => 1199
[custom_price] => 16.83
)
[2] => Array
(
[id] => 1176
[custom_price] => 16.83
)
[3] => Array
(
[id] => 1173
[custom_price] => 11.73
)
[4] => Array
(
[id] => 1170
[custom_price] => 22.5
)
)
Run Code Online (Sandbox Code Playgroud)
我如何从 .. 高到低 & 从低到高 .. 按 custom_price 排序
我有一个数组如下,我想按键"攻击"的值来命令该数组.数组的第一个键是(15, 13, 18)来自数据库的某个特定项的ID,因此我不希望在对数组进行排序时更改这些键.任何帮助将不胜感激.
这是数组:
$data = array(
'15' => array(
'attack' => '45', 'defence' => '15', 'total' => '10'
),
'13' => array(
'attack' => '25', 'defence' => '15', 'total' => '10'
),
'18' => array(
'attack' => '35', 'defence' => '15', 'total' => '10'
)
);
Run Code Online (Sandbox Code Playgroud) 假设我有这个数组:
$array = array(
array("id" => 7867867, "animal" => "Dog"),
array("id" => 3452342, "animal" => "Lion"),
array("id" => 1231233, "animal" => "Lion"),
array("id" => 5867867, "animal" => "Dog"),
array("id" => 1111111, "animal" => "Zeebra"),
array("id" => 2222222, "animal" => "Cat"),
array("id" => 3333333, "animal" => "Cat"),
array("id" => 4444444, "animal" => "Zeebra")
);
Run Code Online (Sandbox Code Playgroud)
现在我一直在尝试做的是使用php排序函数,以便能够根据特定规则对其进行排序(不是按字母顺序)
客户希望这些信息按"Lion first,Dog second,Zeebra third,Cat 4th"排序.
像这样的东西:
$array = array(
array("id" => 3452342, "animal" => "Lion"),
array("id" => 1231233, "animal" => "Lion"),
array("id" => 7867867, "animal" => …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的关联数组。
Array
(
[0] => Array
(
[id] => 1
[name] => Admin
[email] => admin@admin.com
[group] => Admin
[href] => http://localhost/teradasys/index.php/users/user/user_info?&user_id=1
)
[1] => Array
(
[id] => 2
[name] => rochellecanale
[email] => rochellecanale11@gmail.com
[group] =>
[href] => http://localhost/teradasys/index.php/users/user/user_info?&user_id=2
)
[2] => Array
(
[id] => 3
[name] => symfony
[email] => chelle@flax.ph
[group] =>
[href] => http://localhost/teradasys/index.php/users/user/user_info?&user_id=3
)
[3] => Array
(
[id] => 4
[name] => jolopeterson
[email] => jolo@flax.ph
[group] =>
[href] => http://localhost/teradasys/index.php/users/user/user_info?&user_id=4
) …Run Code Online (Sandbox Code Playgroud) 你好朋友,我有一个看起来像这样的数组:
array:3 [?
0 => array:6 [?
"date" => "2016-05-31 15:08:33"
0 => "31 May 16"
1 => "aze"
2 => "2"
3 => "hi"
4 => "487841464704194.jpg"
]
1 => array:6 [?
"date" => "2016-05-31 15:26:09"
0 => "31 May 16"
1 => "aze"
2 => "2"
3 => "hey"
4 => "487841464704194.jpg"
]
2 => array:6 [?
"date" => "2016-06-01 11:33:06"
0 => "01 Jun 16"
1 => "aze"
2 => "2"
3 => "Dm me please"
4 …Run Code Online (Sandbox Code Playgroud) 这是我从Google日历中显示的用于显示事件的多维数组.
Array
(
[items] => Array
(
[0] => Array
(
[status] => confirmed
[summary] => Let's go swimming!
[start] => Array
(
[dateTime] => 2011-12-30T09:00:00-05:00
)
[end] => Array
(
[dateTime] => 2011-12-30T10:00:00-05:00
)
)
[1] => Array
(
[status] => confirmed
[summary] => red wine
[start] => Array
(
[dateTime] => 2011-12-28T06:00:00-05:00
)
[end] => Array
(
[dateTime] => 2011-12-28T07:00:00-05:00
)
)
[2] => Array
(
[status] => confirmed
[summary] => Christmas
[start] => Array
(
[dateTime] => …Run Code Online (Sandbox Code Playgroud)