RE: [PHP] Array sort question
[snip] How can I sort a 2 dimensional array by number of elements? [/snip] Start by RTFM http://www.php.net/manual/en/function.count.php
Re: [PHP] Array sort question
[EMAIL PROTECTED] wrote: [snip] How can I sort a 2 dimensional array by number of elements? [/snip] Start by RTFM http://www.php.net/manual/en/function.count.php I love how infinitely helpful people on this mailing list are. It's a wonder people are being turned off to PHP. There's no one here willing to help new people more than throwing them RTFM responses. -- Jeremy Privett Director of Product Development Zend Certified Engineer Completely Unique [EMAIL PROTECTED] Phone: 303.415.2592 Fax: 303.415.2597 Web: www.completelyunique.com This email may contain confidential and privileged material for the sole use of the intended recipient. Any review or distribution by others is strictly prohibited. If you are not the intended recipient please contact the sender and delete all copies. Your compliance is appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Array sort question
[snip] I love how infinitely helpful people on this mailing list are. It's a wonder people are being turned off to PHP. There's no one here willing to help new people more than throwing them RTFM responses. [/snip] Are you new here? I would rather teach a man how to fish than give him his supper on a silver platter. The OP did not show one ounce of having tried to find the answer on his own, he just wanted us to write the code for him. This same exact thing happens every few months, people get chastised for aa RTFM answer when that is the most appropriate answer. I didn't see you jump up with an answer there Sparky. Nope, your response was almost worthless. I, at least, gave the man a place to start looking for answers. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array sort question
Sometimes I just need a point in the right direction. So RTFM is not so bad. Erik On Feb 28, 2006, at 11:26 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: [snip] I love how infinitely helpful people on this mailing list are. It's a wonder people are being turned off to PHP. There's no one here willing to help new people more than throwing them RTFM responses. [/snip] Are you new here? I would rather teach a man how to fish than give him his supper on a silver platter. The OP did not show one ounce of having tried to find the answer on his own, he just wanted us to write the code for him. This same exact thing happens every few months, people get chastised for aa RTFM answer when that is the most appropriate answer. I didn't see you jump up with an answer there Sparky. Nope, your response was almost worthless. I, at least, gave the man a place to start looking for answers. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array sort question
[EMAIL PROTECTED] wrote: [snip] I love how infinitely helpful people on this mailing list are. It's a wonder people are being turned off to PHP. There's no one here willing to help new people more than throwing them RTFM responses. [/snip] Are you new here? I would rather teach a man how to fish than give him his supper on a silver platter. The OP did not show one ounce of having tried to find the answer on his own, he just wanted us to write the code for him. This same exact thing happens every few months, people get chastised for aa RTFM answer when that is the most appropriate answer. I didn't see you jump up with an answer there Sparky. Nope, your response was almost worthless. I, at least, gave the man a place to start looking for answers. I agree with you there. My response wasn't more helpful than yours, but you could've given him a more appropriate answer than RTFM with a link the the count function. I agree with you about not writing anyone's code for them, but you could at least be a little less harsh in your response to new people. RTFM is not exactly the best way to get people enthusiastic about things... It usually just pisses them off. Also, links to other functions to help out like http://www.php.net/usort or http://www.php.net/array_multisort would've helped out more, as well. -- Jeremy Privett Director of Product Development Zend Certified Engineer Completely Unique [EMAIL PROTECTED] Phone: 303.415.2592 Fax: 303.415.2597 Web: www.completelyunique.com This email may contain confidential and privileged material for the sole use of the intended recipient. Any review or distribution by others is strictly prohibited. If you are not the intended recipient please contact the sender and delete all copies. Your compliance is appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array sort question
Saline Erik wrote: Sometimes I just need a point in the right direction. So RTFM is not so bad. Erik If you say so. In that case, jblanchard, I apologize for my outburst. -- Jeremy Privett Director of Product Development Zend Certified Engineer Completely Unique [EMAIL PROTECTED] Phone: 303.415.2592 Fax: 303.415.2597 Web: www.completelyunique.com This email may contain confidential and privileged material for the sole use of the intended recipient. Any review or distribution by others is strictly prohibited. If you are not the intended recipient please contact the sender and delete all copies. Your compliance is appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array sort question
Jeremy Privett wrote: [EMAIL PROTECTED] wrote: [snip] How can I sort a 2 dimensional array by number of elements? [/snip] Start by RTFM http://www.php.net/manual/en/function.count.php I love how infinitely helpful people on this mailing list are. It's a wonder people are being turned off to PHP. There's no one here willing to help new people more than throwing them RTFM responses. My, you were helpful. -- John C. Nichel IV Programmer/System Admin (ÜberGeek) Dot Com Holdings of Buffalo 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Array sort question
[snip] If you say so. In that case, jblanchard, I apologize for my outburst. [/snip] Apology accepted. Look, several of us have been on this list for years and have helped several others through their issues. Mailing lists like this (try a C++ newsgroup for example) are much more merciless than some of us here, we have toned it in the past year or so. Folks here volunteer a lot of their time and are less likely to help those that will not help themselves. The array sorting suggestions you provide will not sort based on the number of items in each array, which is what the OP wanted. He will have to count each array and then order the arrays by the number of objects contained in each. He could make an array of the arrays and go in that direction. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array sort question
On 28/02/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: The array sorting suggestions you provide will not sort based on the number of items in each array, which is what the OP wanted. That's not entirely fair. I would have said his usort() suggestion was a better pointer than a link to count() - which gives no hint as to how to sort the list, which is after all what the OP's trying to do. ObSuggestion: function byLength($a, $b) { return sizeof($a) - sizeof($b); } usort($rgArray, 'byLength');
RE: [PHP] Array sort question
[snip] That's not entirely fair. I would have said his usort() suggestion was a better pointer than a link to count() - which gives no hint as to how to sort the list, which is after all what the OP's trying to do. ObSuggestion: function byLength($a, $b) { return sizeof($a) - sizeof($b); } usort($rgArray, 'byLength'); Well said, after all there is more than one way to skin a cat. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Array sort question
snip I would rather teach a man how to fish than give him his supper on a silver platter. /snip Write his code and you can reduce his frustration for a day, but teach him to program and you'll frustrate him for life. tedd -- http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array sort question
On Fri, 1 Oct 2004 22:44:50 -0400, Paul Bissex [EMAIL PROTECTED] wrote: On Fri, 1 Oct 2004 19:12:30 -0700, Ed Lazor [EMAIL PROTECTED] wrote: Any ideas on how I could sort this array by Title? $menu[1][ID] = 5; $menu[1][Title] = Test 1; $menu[2][ID] = 3; $menu[2][Title] = Test 4; uasort() is what you need here. Also see the usort() documentation page for an example of how to write the comparison callback function that you pass to uasort(). pb -- paul bissex, e-scribe.com -- database-driven web development 413.585.8095 69.55.225.29 01061-0847 72°39'71W 42°19'42N -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jasper Howard - Database Administration ApexEleven.com 530 559 0107 --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array sort question
Sorry for the empty reply (miss slide of the finger on my touch pad). You can use array_multisort(); The code would look something like this, remember, this is untested code so be warned before any flaming is done: //CODE //You need to restructure your array like this: $menu[ID][1] = 5; $menu[Title][1] = Test 1; $menu[ID][2] = 3; $menu[Title][2] = Test 4; //Then run array_multisort array_multisort($menu['Title'],$menu['ID']); //END CODE Like this it will sort alphabetically or numerically (which ever needed) ascending. You can put tags after the first variable like this: array_multisort($menu['Title'],SORT_ASC,SORT_STRING,$menu['ID']); If there are any more keys in the $menu array you need to list them after the $menu['ID'] key so they will be sorted according to the $menu['Title'] key. The first key you put into array_multisort() is the one that the rest get sorted by. -Jasper Howard On Fri, 1 Oct 2004 22:44:50 -0400, Paul Bissex [EMAIL PROTECTED] wrote: On Fri, 1 Oct 2004 19:12:30 -0700, Ed Lazor [EMAIL PROTECTED] wrote: Any ideas on how I could sort this array by Title? $menu[1][ID] = 5; $menu[1][Title] = Test 1; $menu[2][ID] = 3; $menu[2][Title] = Test 4; uasort() is what you need here. Also see the usort() documentation page for an example of how to write the comparison callback function that you pass to uasort(). pb -- paul bissex, e-scribe.com -- database-driven web development 413.585.8095 69.55.225.29 01061-0847 72°39'71W 42°19'42N -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jasper Howard - Database Administration ApexEleven.com 530 559 0107 --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] array sort question
Thanks for the example using array_multisort. I'd been wondering how I could use that function to do what I want. It looks like it's more flexible in the long run, but I was able to use Paul's recommendation to do what I want. Here's the code I ended up using: function cmp ($a, $b) { return strcmp($a[Title], $b[Title]); } uasort($list, cmp); -Ed -Original Message- Sorry for the empty reply (miss slide of the finger on my touch pad). You can use array_multisort(); The code would look something like this, remember, this is untested code so be warned before any flaming is done: //CODE //You need to restructure your array like this: $menu[ID][1] = 5; $menu[Title][1] = Test 1; $menu[ID][2] = 3; $menu[Title][2] = Test 4; //Then run array_multisort array_multisort($menu['Title'],$menu['ID']); //END CODE Like this it will sort alphabetically or numerically (which ever needed) ascending. You can put tags after the first variable like this: array_multisort($menu['Title'],SORT_ASC,SORT_STRING,$menu['ID']); If there are any more keys in the $menu array you need to list them after the $menu['ID'] key so they will be sorted according to the $menu['Title'] key. The first key you put into array_multisort() is the one that the rest get sorted by. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array sort question
On Fri, 1 Oct 2004 19:12:30 -0700, Ed Lazor [EMAIL PROTECTED] wrote: Any ideas on how I could sort this array by Title? $menu[1][ID] = 5; $menu[1][Title] = Test 1; $menu[2][ID] = 3; $menu[2][Title] = Test 4; uasort() is what you need here. Also see the usort() documentation page for an example of how to write the comparison callback function that you pass to uasort(). pb -- paul bissex, e-scribe.com -- database-driven web development 413.585.8095 69.55.225.29 01061-0847 72°39'71W 42°19'42N -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php