Pages

2009年12月24日 星期四

Notice: Use of undefined constant

$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);

執行後會出現Notice: Use of undefined constant compare - assumed 'compare'

解決方式:
usort($products, 'compare');

沒有留言:

張貼留言