我有以下数组:
$data['array'] = array(
1 => array(
'currency_name' => 'USD',
'totals' => '310.00 USD'
),
24 => array(
'currency_name' => 'EUR',
'totals' => '200.00 EUR'
),
26 => array(
'currency_name' => 'GBP',
'totals' => '100.00 GBP'
)
);
我想currency_name
按键排序,我使用了以下功能:
// sort the array by currency_name key
$sort = array();
foreach ($data['array'] as $i => $row)
{
$sort[$i] = $row['currency_name'];
}
array_multisort($sort, SORT_NATURAL, $data['array']);
输出:
Array
(
[array] => Array
(
[0] => Array
(
[currency_name] => EUR
[totals] => 200.00 EUR
)
[1] => Array
(
[currency_name] => GBP
[totals] => 100.00 GBP
)
[2] => Array
(
[currency_name] => USD
[totals] => 310.00 USD
)
)
)
预期的:
Array
(
[array] => Array
(
[24] => Array
(
[currency_name] => EUR
[totals] => 200.00 EUR
)
[26] => Array
(
[currency_name] => GBP
[totals] => 100.00 GBP
)
[1] => Array
(
[currency_name] => USD
[totals] => 310.00 USD
)
)
)
这是重新索引数组,我不想要。我以后需要这些钥匙。
注意:
* 我上面使用的方法是这个
* 我需要SORT_NATURAL
这个函数,因为我也将这个函数用于其他字符串。