# Can *sort functions return the sorted array ?

- Thread: https://externals.io/message/13504
- Original archive: https://news-web.php.net/php.internals/13504
- Started by Fulax on 2004-10-25T12:49:38+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #13504 — Fulax — 2004-10-25T12:49:38+00:00

URL: https://externals.io/message/13504#13504

Hi,

I wonder if it will be possible to add an extra argument to the *sort 
functions to get the sorted array directly.
At the moment I have made my own function to do this, here is an example 
with natsort :

function arrnatsort($a_array)
{
    if(natsort($a_array))
        return $a_array;
    else
        return false;
}

I think it will more convenient to simply call $array = 
natsort($array,true);, when you need to combine functions, like this :
$sSortedString =  join(',',arrnatsort(explode(',',$sString)));

At the moment, the way is to create an auxilliary function, or to make 
more steps :

$aTemArray = explode(',',$sString);
natsort($aTempArray);
$sSortedString =  join(',',$aTempArray);
unset $aTempArray;

Does it make sense to add the possibility for an extra argument ? Like 
highlight_string function, the extra argument return the string instead 
of displaying it.

Thanks in advance, and sorry for my crapy English

Cyprien

---

## #13508 — Ron Korving — 2004-10-25T17:03:03+00:00

URL: https://externals.io/message/13504#13508 · In reply to: #13504

I'm not a fan of this. I don't think it's appropriate to just add parameters
to functions all the time just because you don't like the fact that it's
call-by-reference.

Ron

"Fulax" <fulax@naedev.naellia.org> wrote in message
news:417CF662.9080204@naedev.naellia.org...
> Hi,
>
> I wonder if it will be possible to add an extra argument to the *sort
> functions to get the sorted array directly.
> At the moment I have made my own function to do this, here is an example
> with natsort :
>
> function arrnatsort($a_array)
> {
>     if(natsort($a_array))
>         return $a_array;
>     else
>         return false;
> }
>
> I think it will more convenient to simply call $array =
> natsort($array,true);, when you need to combine functions, like this :
> $sSortedString =  join(',',arrnatsort(explode(',',$sString)));
>
> At the moment, the way is to create an auxilliary function, or to make
> more steps :
>
> $aTemArray = explode(',',$sString);
> natsort($aTempArray);
> $sSortedString =  join(',',$aTempArray);
> unset $aTempArray;
>
> Does it make sense to add the possibility for an extra argument ? Like
> highlight_string function, the extra argument return the string instead
> of displaying it.
>
> Thanks in advance, and sorry for my crapy English
>
> Cyprien
