使用 array_multisort 对整数进行升序排序,并相应地对相应的字符串进行排序 (php)

Using array_multisort to sort integer ascending and sort corresponding string accordingly (php)

如何使用 array_multisort 将价格从最低到最高排序,然后使用该排序顺序对其相应的标题进行排序?

数组

$pricearray = array(4.00, 56.99, 3.19);
$headerarray = array('four', 'fifty-six', 'three');

期望输出

$pricearray = array(3.19, 4.00, 56.99);
$headerarray = array('three', 'four', 'fifty-six');

我的尝试

array_multisort($headerarray, $pricearray, SORT_ASC);

按升序 $pricearray 排序(默认),array_multisort 将用它对 $headerarray 排序:

array_multisort($pricearray, $headerarray);

要指定顺序,请将其用作数组后的参数:

array_multisort($pricearray, SORT_ASC, $headerarray);

请参阅 manual,其中指出某些参数可以交换或省略:

array1_sort_order The order used to sort the previous array argument. Either SORT_ASC to sort ascendingly or SORT_DESC to sort descendingly.

This argument can be swapped with array1_sort_flags or omitted entirely, in which case SORT_ASC is assumed.

array1_sort_flags Sort options for the previous array argument:

This argument can be swapped with array1_sort_order or omitted entirely, in which case SORT_REGULAR is assumed.