Start New Discussion within our Web Development Community

I am workin on an which i need to know in what order array is sorted after sortig using function sort($array);

Hmm, maybe I'm not understanding your question, can you please post your code and spot the problem?

if i am having the array $ab=array('0'=>'10','1'=>'5','2'=>'8') .and i sorts it using the array by $ba=sort($ab); then i need two result 1st (5,8,10) and second (1,2,0).the second is order inwhich the values is arranged.

but how can i get the 1st value of the sorted array?i cant use $ba[0] for 5.

A foreach loop will work:

foreach($ab as $k => $v)
    echo "$k  -  $v \n";

If you wan to group them in different arrays then use:

$keys = array();
$values = array();
foreach($ab as $k => $v)
    $keys[] = $k;
    $values[] = $v;


Or better use array_keys() and array_values():

$ab = array('0'=>'10','1'=>'5','2'=>'8');
$ba = $ab;



This question has already been answered. Start a new discussion instead.