Re: note 86552 rejected and deleted from function.array-multisort by notes editor danbrown
| From: | Matt Rohland | Date: | Thu, 23 Oct 2008 16:55:31 +0000 |
| Subject: | Re: note 86552 rejected and deleted from function.array-multisort by notes editor danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145662@lists.php.net to get a copy of this message | ||
This was not a question... It was a method... I just used a question to
illustrate the point, please read it again and reconsider.
On Thu, Oct 23, 2008 at 11:50 AM, <php-notes@lists.php.net> wrote:
> You are receiving this email because your note posted
> to the online PHP manual has been removed by one of the editors.
>
> Read the following paragraphs carefully, because they contain
> pointers to resources better suited for requesting support or
> reporting bugs, none of which are to be included in manual notes
> because there are mechanisms and groups in place to deal with
> those issues.
>
> The user contributed notes are not an appropriate place to
> ask questions, report bugs or suggest new features; please
> use the resources listed on <http://php.net/support>
> for those purposes. This was clearly stated in the page
> you used to submit your note, please carefully re-read
> those instructions before submitting future contributions.
>
> Bug submissions and feature requests should be entered at
> <http://bugs.php.net/>. For documentation errors use the
> bug system, and classify the bug as "Documentation problem".
> Support and ways to find answers to your questions can be found
> at <http://php.net/support>.
>
> Your note has been removed from the online manual.
>
> ----- Copy of your note below -----
>
> I looked on some forms for an answer to this simple problem and couldn't
> find one so I came up with a solution that may help in some situations.
>
> How do you sort an array by a field in that array and resolve numeric ties
> randomly?
>
> Code:
> <?php
>
> foreach($list as $temp_list)
> {
> $sort_aux[] = ($temp_list['column_to_sort_by']+(rand(1, 9)/10));
> }
> array_multisort($sort_aux, SORT_NUMERIC, $list);
>
> ?>
>
> Example:
>
> $list[]=array('name'=>'Tom', 'score'=>3);
> $list[]=array('name'=>'Sam', 'score'=>3);
> $list[]=array('name'=>'Joey', 'score'=>1);
>
> Explanation:
> I took an existing example found above that shows how to sort an array by
> one of it's columns/fields.
> I just added: "+(rand(1,9)/10)" To randomly add .1 through .9 to their
> score to resolve the tie. (Obviously this specific example only works if
> you're sorting by an integer... so you may need to modify it to suit your
> needs.)
>
> Hope this helps someone.
>