I am storing array in the following way
$pos[$k] = $total[$k]." / ".$posts_ids[$k]." / ".$time[$k];
I am using following way to extract the value from the pos array.
$a = $b = array();
foreach ($pos as $key => $value){
list($a[$key], $b[$key], $t[$key]) = explode('/', $value);
array_multisort($a, SORT_DESC, SORT_NUMERIC, $b ,$t);
}
But i am not able to extract the value of the variable $t as well as not able to sort it without change there position of array.
You haven’t defined
tas an array in your code, which shouldn’t be a problem unless you have no values (but, in that case, you would get a warning).As for multisort, the correct syntax would be
but it’s not very clear what you want to do, and it might be more convenient to organize differently the parsing of values (e.g. in a multidimensional array instead of multiple arrays, or use a custom sort function).
That is by design.
array_multisortsorts on the first array you pass, which is$a. The corresponding elements in the other arrays will be sorting according to the position of the items in$a.For example if the first element of
$ais the smallest, it will be placed last inSORT_DESC. But since the first element of$ais last, the last element of$twill also be put last within$t, whatever its value.If you want
$tto “rule” the sort, you must put it first.If you want all three arrays to be independently sorted, you must not use
array_multisort.