Results 1 to 3 of 3
-
01-27-2005, 01:41 AM #1Newbie
- Join Date
- Sep 2004
- Location
- Sydney
- Posts
- 7
(PHP) Notice: Use of undefined constant
I'm a noob here, reading through SAMs PHP & MySQL Web Development. I can't get around this problem.
PHP Code:$products = array( array("TIR", "Tires", 100),
array( "OIL", "Oil", 10),
array( "SPK", "Spark Plugs", 4));
function compare($x, $y)
{
if ( $x[1] == $y[1] )
return 0;
else if ( $x[1] < $y[1] )
return -1;
else
return 1;
}
usort($products, compare);
Outputs:
Notice: Use of undefined constant compare - assumed 'compare' in C:\Inetpub\wwwroot\PHP\usort.php on line 16
-
01-27-2005, 02:05 AM #2Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
Change to usort($products, 'compare');
Any string not encapsulated in quotes is considered a constant, and that message is just a Notice telling you that PHP thinks compare is a constant, but its not defined anywhere.
-
01-27-2005, 02:28 AM #3Newbie
- Join Date
- Sep 2004
- Location
- Sydney
- Posts
- 7
That did the trick, thanks fyre!