Hi,
I am not getting the correct results on the number of calls to the function (compare). I placed a counter ($NumberofCalls) and it only shows one call to the function. Is that correct?
Also, I am not getting the correct result of the comparison for my arrays? It constantely gives me "1", which I don't think is the right answer.
Here is my code:
<?php
$products = array ( array ( 'TIR', 'Tires', 100 ),
array ( 'OIL', 'Oil', 10 ),
array ( 'SPK', 'Spark Plugs', 4 ) );
$NumberofCalls = 0;
function compare($x, $y)
{
$NumberofCalls++;
print ('This is the '.$NumberofCalls.' call to the function.<br />');
if ( $x[1] == $y[1] )
print ('Comparing '.$x[1].' to '.$y[1].' => '.( $x[1] == $y[1] ).'<br>');
else if ( $x[1] < $y[1] )
print ('Comparing '.$x[1].' to '.$y[1].' => '.( $x[1] < $y[1] ).'<br>');
else
print ('Comparing '.$x[1].' to '.$y[1].' => '.( $x[1] > $y[1] ).'<br>');
}
print ('-----------IN------------');
print ('<pre>');
print_r ($products);
print ('<pre>');
print ('-----------RESULT-------------<br />');
echo ( 'Function Result = '.usort ($products, 'compare') );
echo '<br />';
print ('<br />-----------OUT------------<br />');
print ('<pre>');
print_r ($products);
print ('<pre>');
?>
ty
masood
p.s. Can you tell me how I can put my code that I like for people in forum to see in a separate box?