这是我的数组我需要以相反的顺序获取数组如何按相反的顺序对它进行排序我需要使用数组的索引对其进行排序在下面的数组中它有两个索引[0]和[1] ]我需要反向排序,排序后索引[0]应显示[1]和[1]的记录应显示[0]的记录
我已经在下面展示了我的阵列帮助我解决它
Array
(
[0] => Array
(
[0] => stdClass Object
(
[user_id] => 103
[full_name] => newuser
[mobile_number] => 4152638596
[country] =>
[email] => remo@aj.net
[password] => MTIzNDU2
[secret_pin] => MTIzNDU2
[date_of_join] => 2016-10-14 13:52:38
[status] => 1
[email_verification] => 1
[bitcoin_address] => mhvnsceqMHoQqv9vDfXc7Y97d58R8CWA5S
[user_type] => 1
[last_login] => 2016-10-15 10:44:02.000000
[logged_in] => 1
[otp_code] => 0
[reference_code] => 597711
[direct_id] => 1
[parent_id] => 1
[root_id] => 1
[due_time] => 2016-10-15 13:52:38
[badge] => 2
)
)
[1] => Array
(
[0] => stdClass Object
(
[user_id] => 1
[full_name] => admin
[mobile_number] => 8252525263
[country] =>
[email] => admin@mmmhelp4.com
[password] => MTIzNDU2
[secret_pin] => MTIzNDU2
[date_of_join] => 2016-10-07 17:51:24
[status] => 1
[email_verification] => 1
[bitcoin_address] => mhvnsceqMHoQqv9vDfXc7Y97d58R8CWA5S
[user_type] => 2
[last_login] => 2016-10-12 10:46:35.000000
[logged_in] => 1
[otp_code] => 0
[reference_code] => 111111
[direct_id] => 0
[parent_id] => 0
[root_id] => 0
[due_time] => 2016-10-12 09:24:18
[badge] => 1
)
)
)
var_export()结果如下所示
array (
0 =>
array (
0 =>
stdClass::__set_state(array(
'user_id' => '103',
'full_name' => 'newuser',
'mobile_number' => '4152638596',
'country' => '',
'email' => 'remo@aj.net',
'password' => 'MTIzNDU2',
'secret_pin' => 'MTIzNDU2',
'date_of_join' => '2016-10-14 13:52:38',
'status' => '1',
'email_verification' => '1',
'bitcoin_address' => 'mhvnsceqMHoQqv9vDfXc7Y97d58R8CWA5S',
'user_type' => '1',
'last_login' => '2016-10-15 10:44:02.000000',
'logged_in' => '1',
'otp_code' => '0',
'reference_code' => '597711',
'direct_id' => '1',
'parent_id' => '1',
'root_id' => '1',
'due_time' => '2016-10-15 13:52:38',
'badge' => '2',
)),
),
1 =>
array (
0 =>
stdClass::__set_state(array(
'user_id' => '1',
'full_name' => 'admin',
'mobile_number' => '8252525263',
'country' => '',
'email' => 'admin@mmmhelp4.com',
'password' => 'MTIzNDU2',
'secret_pin' => 'MTIzNDU2',
'date_of_join' => '2016-10-07 17:51:24',
'status' => '1',
'email_verification' => '1',
'bitcoin_address' => 'mhvnsceqMHoQqv9vDfXc7Y97d58R8CWA5S',
'user_type' => '2',
'last_login' => '2016-10-12 10:46:35.000000',
'logged_in' => '1',
'otp_code' => '0',
'reference_code' => '111111',
'direct_id' => '0',
'parent_id' => '0',
'root_id' => '0',
'due_time' => '2016-10-12 09:24:18',
'badge' => '1',
)),
),
)
答案 0 :(得分:3)
您的解决方案是array_reverse()
http://php.net/manual/en/function.array-reverse.php
$arr = array (
0 =>
array (
0 =>
array(
'user_id' => '103',
'full_name' => 'newuser',
'mobile_number' => '4152638596',
'country' => '',
'email' => 'remo@aj.net',
'password' => 'MTIzNDU2',
'secret_pin' => 'MTIzNDU2',
'date_of_join' => '2016-10-14 13:52:38',
'status' => '1',
'email_verification' => '1',
'bitcoin_address' => 'mhvnsceqMHoQqv9vDfXc7Y97d58R8CWA5S',
'user_type' => '1',
'last_login' => '2016-10-15 10:44:02.000000',
'logged_in' => '1',
'otp_code' => '0',
'reference_code' => '597711',
'direct_id' => '1',
'parent_id' => '1',
'root_id' => '1',
'due_time' => '2016-10-15 13:52:38',
'badge' => '2',
),
),
1 =>
array (
0 =>
array(
'user_id' => '1',
'full_name' => 'admin',
'mobile_number' => '8252525263',
'country' => '',
'email' => 'admin@mmmhelp4.com',
'password' => 'MTIzNDU2',
'secret_pin' => 'MTIzNDU2',
'date_of_join' => '2016-10-07 17:51:24',
'status' => '1',
'email_verification' => '1',
'bitcoin_address' => 'mhvnsceqMHoQqv9vDfXc7Y97d58R8CWA5S',
'user_type' => '2',
'last_login' => '2016-10-12 10:46:35.000000',
'logged_in' => '1',
'otp_code' => '0',
'reference_code' => '111111',
'direct_id' => '0',
'parent_id' => '0',
'root_id' => '0',
'due_time' => '2016-10-12 09:24:18',
'badge' => '1',
),
),
);
$k = array_reverse($arr);
echo '<pre>';
print_r($k);
运行它并查看所需结果。我已删除stdClass
进行测试。你可以运行自己的