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

i think their is no solution for it.

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.

For that you need asort():

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

And you get:

Array
(
    [1] => 5
    [2] => 8
    [0] => 10
)

http://www.php.net/manual/en/function.asort.php
bye!

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

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.