Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004
    Location
    Sydney
    Posts
    7

    Question (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($productscompare); 
    I'ts supposed to sort the arrays inside $products

    Outputs:

    Notice: Use of undefined constant compare - assumed 'compare' in C:\Inetpub\wwwroot\PHP\usort.php on line 16

  2. #2
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    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.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  3. #3
    Join Date
    Sep 2004
    Location
    Sydney
    Posts
    7
    That did the trick, thanks fyre!

  4. Newsletters

    Subscribe Now & Get The WHT Quick Start Guide!

Related Posts from theWHIR.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •