Re: [PHP] usort within a class

2011-04-18 Thread Stuart Dallas
it is. I've gone over the usort() docs and read the user comments, and the only thing I've found so far which looked like it was the same issue gave this example: bo at erichsen dot com 20-Mar-2001 01:16 when using usort to refer to a function inside a class i have succesfully used: ?php

Re: [PHP] usort within a class

2011-04-18 Thread Ashley Sheridan
to refer to a function inside a class i have succesfully used: ?php usort($myarray,array($this,cmp)); ? Unfortunately, that doesn't work either. A basic example is as follows: class Search_model extends Model { function get_results($q) { if(strlen($q)) { $results

Re: [PHP] usort within a class

2011-04-18 Thread Stuart Dallas
: bo at erichsen dot com 20-Mar-2001 01:16 when using usort to refer to a function inside a class i have succesfully used: ?php usort($myarray,array($this,cmp)); ? Unfortunately, that doesn't work either. A basic example is as follows: class Search_model extends

Re: [PHP] usort for sorting an array of objects

2008-12-10 Thread Stut
On 10 Dec 2008, at 04:15, German Geek wrote: I need to sort an array of objects. I found this ( at a url that didnt let me send this msg... ) and I would know how to do it, but I believe there might be a cleaner, more elegant way to do it. In Java, you just need to implement the interface

Re: [PHP] usort for sorting an array of objects

2008-12-10 Thread German Geek
On Wed, Dec 10, 2008 at 10:27 PM, Stut [EMAIL PROTECTED] wrote: On 10 Dec 2008, at 04:15, German Geek wrote: I need to sort an array of objects. I found this ( at a url that didnt let me send this msg... ) and I would know how to do it, but I believe there might be a cleaner, more elegant

Re: [PHP] usort for sorting an array of objects

2008-12-10 Thread Robert Cummings
On Thu, 2008-12-11 at 01:31 +1300, German Geek wrote: On Wed, Dec 10, 2008 at 10:27 PM, Stut [EMAIL PROTECTED] wrote: On 10 Dec 2008, at 04:15, German Geek wrote: I need to sort an array of objects. I found this ( at a url that didnt let me send this msg... ) and I would know how to do

Re: [PHP] usort for sorting an array of objects

2008-12-10 Thread Shiplu
may be you can design a class. interface ISortable{ public sort(); public compare($a,$b); } SortableList implements ISortable { } -- Blog: http://talk.cmyweb.net/ Follow me: http://twitter.com/shiplu -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:

Re: [PHP] usort for sorting an array of objects

2008-12-10 Thread ceo
You can use a (base) object Comparable with a method compareTo as the callback function for http://php.net/usort That gives you 99% of what you want, for the tiny price of having to pass in the array('Comparable','compareTo') as the callback arg. Given that one frequently calls usort and

Re: [PHP] usort for sorting an array of objects

2008-12-10 Thread German Geek
On Thu, Dec 11, 2008 at 6:43 AM, Robert Cummings [EMAIL PROTECTED]wrote: On Thu, 2008-12-11 at 01:31 +1300, German Geek wrote: On Wed, Dec 10, 2008 at 10:27 PM, Stut [EMAIL PROTECTED] wrote: On 10 Dec 2008, at 04:15, German Geek wrote: I need to sort an array of objects. I found

Re: [PHP] usort for sorting an array of objects

2008-12-10 Thread Shiplu
PHP is a scripting language. Everytime the compiler has to parse the source. You can not except true OOP performance. OOP behavior is okay. If performance is the main factor, an C extension will do that. -- Blog: http://talk.cmyweb.net/ Follow me: http://twitter.com/shiplu -- PHP General

Re: [PHP] usort for sorting an array of objects

2008-12-10 Thread ceo
Inefficiency for me is when it takes longer to code. How long can this take? Even if you go full-blown with an Interface and static methods that have to be fleshed out in the implementations, you're still talking about an hour or so. Quit complaining and start typing. :-) PHP is a

Re: [PHP] usort for sorting an array of objects

2008-12-10 Thread German Geek
On Thu, Dec 11, 2008 at 12:28 PM, [EMAIL PROTECTED] wrote: Inefficiency for me is when it takes longer to code. How long can this take? That's why i like PHP. It's very quick to do stuff in, even if arrays are not always the ultimate data structure, they're easy to handle with all the nice

Re: [PHP] usort for sorting an array of objects

2008-12-10 Thread Robert Cummings
On Thu, 2008-12-11 at 11:44 +1300, German Geek wrote: On Thu, Dec 11, 2008 at 6:43 AM, Robert Cummings [EMAIL PROTECTED]wrote: On Thu, 2008-12-11 at 01:31 +1300, German Geek wrote: On Wed, Dec 10, 2008 at 10:27 PM, Stut [EMAIL PROTECTED] wrote: On 10 Dec 2008, at 04:15, German Geek

[PHP] usort for sorting an array of objects

2008-12-09 Thread German Geek
Hi Guys, I need to sort an array of objects. I found this ( at a url that didnt let me send this msg... ) and I would know how to do it, but I believe there might be a cleaner, more elegant way to do it. In Java, you just need to implement the interface Comparable and provide a method called

[PHP] usort inside a class

2008-05-09 Thread It Maq
Hi, i'm trying to build a class that sorts a multidimensional array. I'm using the php function usort. I declared the comparision function as a method of my class but i'm unable to give it as argument to the function usort. this usort($this-arr, $this-cmpi) gaves the following error: usort()

Re: [PHP] usort inside a class

2008-05-09 Thread Richard Heyes
i'm trying to build a class that sorts a multidimensional array. I'm using the php function usort. I declared the comparision function as a method of my class but i'm unable to give it as argument to the function usort. this usort($this-arr, $this-cmpi) gaves the following error: usort()

Re: [PHP] usort inside a class

2008-05-09 Thread It flance
It works thanks a lot! --- On Fri, 5/9/08, Richard Heyes [EMAIL PROTECTED] wrote: From: Richard Heyes [EMAIL PROTECTED] Subject: Re: [PHP] usort inside a class To: [EMAIL PROTECTED] Cc: php-general@lists.php.net Date: Friday, May 9, 2008, 8:47 PM i'm trying to build a class that sorts

[PHP] usort within a class

2006-08-23 Thread Peter Lauri
Hi, Is it possible to have the compare function in a class? I can not get it to work, this is pseudo code: class A { function getArray() { //dosomethingandgetanarray $array = blabla; usort($array, $this-myCompareFunction); //Or maybe A::myCompareFunction }

Re: [PHP] usort within a class

2006-08-23 Thread Robert Cummings
On Thu, 2006-08-24 at 03:13 +0700, Peter Lauri wrote: Hi, Is it possible to have the compare function in a class? I can not get it to work, this is pseudo code: class A { function getArray() { //dosomethingandgetanarray $array = blabla; usort($array,

RE: [PHP] usort within a class

2006-08-23 Thread Peter Lauri
Working perfect, thanks :) I did RTFM but I did miss that :) -Original Message- From: Robert Cummings [mailto:[EMAIL PROTECTED] Sent: Thursday, August 24, 2006 3:46 AM To: Peter Lauri Cc: php-general@lists.php.net Subject: Re: [PHP] usort within a class On Thu, 2006-08-24 at 03:13 +0700

[PHP] usort(): The argument should be an array

2006-02-28 Thread Remember14a
Can anyone comment and fix this error Warning: usort(): The argument should be an array in /home2/wwwabcde/public_html/search/searchfuncs.php on line 300 below is part of the code which gives this error, the line

Re: [PHP] usort(): The argument should be an array

2006-02-28 Thread Robin Vickery
On 28/02/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Can anyone comment and fix this error Warning: usort(): The argument should be an array in /home2/wwwabcde/public_html/search/searchfuncs.php on line 300 [...] usort($res, cmp); Put a print_r($res) above

[PHP] usort(): The argument should be an array

2006-02-28 Thread Remember14a
No this doesnt solve error. let me give you more details to understand problem with the said code. go to this link, please. http://www.abcdefg.us/search/search.php in search enter, Justice, you get response without an error. Now enter law, you get error, pasted below, Warning: usort(): The

Re: [PHP] usort(): The argument should be an array

2006-02-28 Thread Thorsten Suckow-Homberg
$row[4]; $res[$i]['size'] = $row[5]; $res[$i]['weight'] = $result_array[$row[0]]; $i++; } usort($res, cmp); echo mysql_error(); $res['maxweight'] = $maxweight; $res['results'] = $results; return $res; /**/ } ? That's not enough, we need the part that sits above and

Re: [PHP] usort e é together

2004-07-11 Thread Marek Kilimajer
John Taylor-Johnston wrote: I think my problem lies in usort. I have a big honker of an array which I usort. $ausenquiry = e; and $ausenquiry = e; give a separate result. I want to conjoin them. Possible? The same would be true for a and à. usort distinguishes between é and e. Any way around this?

[PHP] parse error: [PHP] usort e é together

2004-07-11 Thread John Taylor-Johnston
I went with this, but am getting a parse error. usort($authors, create_function('$a,$b',' $a = str_replace(array('é', 'à'), array('e', 'a'), $a); $b = str_replace(array('é', 'à'), array('e', 'a'), $b); return strcasecmp($a,$b);')); Anyone see it? I've got headaches from

Re: [PHP] parse error: [PHP] usort e é together

2004-07-11 Thread Marek Kilimajer
I'm sorry, I used unescaped single quotes inside single quoted string, this is right: usort($authors, create_function('$a,$b',' $a = str_replace(array(é, à), array(e, a), $a); $b = str_replace(array(é, à), array(e, a), $b); return strcasecmp($a,$b);')); John

Re: [PHP] parse error: [PHP] usort e é together

2004-07-11 Thread John Taylor-Johnston
Sorry. Still getting a parse error on line 40: 39 usort($authors, create_function('$a,$b',' 40 $a = str_replace(array('é', 'à'), array('e', 'a'), $a); 41 $b = str_replace(array('é', 'à'), array('e', 'a'), $b); 42 return strcasecmp($a,$b);')); Can you have two arrays

Re: [PHP] parse error: [PHP] usort e é together

2004-07-11 Thread Miroslav Hudak (php/ml)
Dunno the original question, but this obviously should be escaped... So the correct code follows... usort($authors, create_function('$a,$b',' $a = str_replace(array(\'é\', \'a\'), array(\'e\', \'a\'), $a); $b = str_replace(array(\'é\', \'a\'), array(\'e\', \'a\'), $b); return

Re: [PHP] usort e é together

2004-07-11 Thread John Taylor-Johnston
http://compcanlit.usherbrooke.ca/new1/db/index.php?ausenquiry=e http://compcanlit.usherbrooke.ca/new1/db/index.php?ausenquiry=é It still sorts é and e separately, but without a parse error: $first = array('à', 'é'); $second = array('a', 'e'); usort($authors, create_function('$a,$b','

Re: [PHP] usort e é together

2004-07-11 Thread Miroslav Hudak (php/ml)
this is slightly changed function of yours, written for better readability... ?php $authors = array('élen', 'Élen', 'Elison', 'ámadeus', 'albert', 'alfred', 'amadeus', 'elen'); function usort_callback($a, $b) { $a = strtolower($a); $b = strtolower($b); $a = str_replace(array('á', 'é'),

Re: [PHP] usort e é together

2004-07-11 Thread Miroslav Hudak (php/ml)
Pardon me for the strtolower line, i've just forgot there... it's 4:30AM here in Slovakia... :/ correct listing follows... ?php $authors = array('élen', 'Élen', 'Elison', 'ámadeus', 'albert', 'alfred', 'amadeus', 'elen'); function usort_callback($a, $b) { $a = str_replace(array('á', 'é'),

Re: [PHP] usort e é together

2004-07-11 Thread John Taylor-Johnston
Thanks! What does var_dump do? (I didn't really understand the manual.) Miroslav Hudak (php/ml) wrote: Pardon me for the strtolower line, i've just forgot there... it's 4:30AM here in Slovakia... :/ correct listing follows... ?php $authors = array('élen', 'Élen', 'Elison', 'ámadeus',

Re: [PHP] usort e é together

2004-07-11 Thread John Taylor-Johnston
Sorry, doesn't work either. http://compcanlit.usherbrooke.ca/new1/db/index.php?ausenquiry=e does not contain those that start with é: http://compcanlit.usherbrooke.ca/new1/db/index.php?ausenquiry=é function usort_callback($a, $b) { $a = str_replace(array('à', 'é'), array('a', 'e'),

[PHP] usort e é together

2004-07-10 Thread John Taylor-Johnston
I think my problem lies in usort. I have a big honker of an array which I usort. $ausenquiry = e; and $ausenquiry = e; give a separate result. I want to conjoin them. Possible? The same would be true for a and à. usort distinguishes between é and e. Any way around this? I don't see any

[PHP] Usort an array.

2003-11-20 Thread Vincent M.
Hello, I have an array like that: $return[0][photo] = monuments_01.jpg $return[1][photo] = monuments_00.jpg $return[2][photo] = monuments_03.jpg $return[3][photo] = monuments_02.jpg $return[4][photo] = monuments_04.jpg If I use the sort function: sort($return) ; I get:

RE: [PHP] Usort an array.

2003-11-20 Thread Jay Frumkin
Try using rsort() Jay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] usort

2003-10-27 Thread Justin Patrin
No need to write your own function, it's already in PHP. :-) What you're looking for it natsort(). It uses natural order string comparison (which takes into account numbers instead of just using characters like a regular search does). There are also lots of other 'nat' functions, such as

[PHP] usort

2003-10-24 Thread Shmuel
Hi, I'm trying sort an array. It has entries like this: file_1.ext file_2.ext file_3.ext file_10.ext file_40.ext and so on. I want to sort them alphabetically first and then by the numbers. If I sort them normally I get them like this: file_1.ext file_10.ext file_2.ext file_3.ext file_40.ext

Re: [PHP] usort

2003-10-24 Thread Curt Zirzow
* Thus wrote Shmuel ([EMAIL PROTECTED]): file_1.ext file_2.ext file_3.ext file_10.ext file_40.ext function mycmp($a, $b) { if ($a == $b) { return 0; } $a_n = preg_match(/\D+(\d+)\D+/, $a, $a_out); $b_n = preg_match(/\D+(\d+)\D+/, $b,

Re: [PHP] usort

2003-10-24 Thread Shmuel
Curt Zirzow wrote: * Thus wrote Shmuel ([EMAIL PROTECTED]): file_1.ext file_2.ext file_3.ext file_10.ext file_40.ext function mycmp($a, $b) { if ($a == $b) { return 0; } $a_n = preg_match(/\D+(\d+)\D+/, $a, $a_out); $b_n = preg_match(/\D+(\d+)\D+/,

Re: [PHP] usort

2003-10-24 Thread David Otton
On Sat, 25 Oct 2003 04:03:12 +0300, you wrote: I don't know what the names are. I just know that there might be numbers. :) It still doesn't work. It gives very odd results with the $x_out variables. ?php function cmp ($a, $b) { if ($a == $b) {

[PHP] Usort

2003-04-03 Thread Jonathan Pitcher
This email is long I apologize for that. It is my code and then what it returns and what I am wanting it to return. I don't think I understand how USORT works or even if I am using the right function for what I am looking for. Thanks in advance for your help Jonathan Pitcher

Re: [PHP] Usort

2003-04-03 Thread Ernest E Vogelsinger
At 23:53 03.04.2003, Jonathan Pitcher said: [snip] This email is long I apologize for that. It is my code and then what it returns and what I am wanting it to return. I don't think I understand how USORT works or even if I am using the right function for

Re: [PHP] Usort

2003-04-03 Thread Jonathan Pitcher
Thank you. I now have it working and it makes sense. Jonathan On Thursday, April 3, 2003, at 04:26 PM, Ernest E Vogelsinger wrote: [snip] The compare callback is expected to return anything 0 if the first value is less than the second (should sort

[PHP] usort crashes

2002-12-30 Thread CeeGee
A quite anusual problem - and I can't figure it out.. My script, using the usort-function works properly on my local php-environment (PHP 4.0.6) but not on my server, running php 4.1.2! I've read in a documentation, that php since 4.1.0 doesn't accept zero as return-value of the compare-function.

[PHP] usort will not take variable

2002-09-19 Thread Robert Miller
Hello, Do you know the answer to this got'tcha? I want to call usort with a variable function name. Basically, I want usort to sort any field I specify. Currently, I'm stuck declaring a pile of functions and calling usort from if/elseif statements. :-( Current: function compname ($a, $b)

[PHP] usort Issues and Classes

2001-02-06 Thread Jason Mowat
Greets, I am playing around with usort and an LDAP class. Basically, I want to sort the results of an LDAP search based on a specific criterion. class CLDAP { var $m_Entries; var $m_LinkIdentifier; ... function Connect() { ... } function Bind() { ... } function