2
Contributors
7
Replies
16
Views
4 Years
Discussion Span
Last Post by cereal
0

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

0

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.

0

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

0

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;
}

print_r($keys);
print_r($values);

Or better use array_keys() and array_values():

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

print_r(array_keys($ba));
print_r(array_values($ba));

Ok?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.