PHP Basics, why does this program show blank pages, where wrong? How do I get it to output a sorted result
This post was last edited by u013071929 on 2013-12-11 22:59:16
$prodects = Array (' TIR ', ' Tires ', 100),
Array (' oil ', ' oil ', 10),
Array (' SPK ', ' Spark plugs ', 4));
function Compare ($x, $y)
{
What is the value of if ($x [1] = = $y [1])//x[1] and y[1]?
{
return 0;
}else if ($x [1]< $y [1])
{
return-1;
}else
{
return 1;
}
}
Usort ($products, ' compare ');
foreach ($products as $key)
{
echo ' | '. $key. ' | ';
}
echo "
";
?>
PHP Basics, why does this program show blank pages, where wrong? How do I get it to output a sorted result,
Share to: more
------Solution--------------------
$ prodects= Array (' TIR ', ' Tires ', 100),
Array (' oil ', ' oil ', 10),
Array (' SPK ', ' Spark plugs ', 4));
Usort ($ Products, ' compare ');
It's clear.
------Solution--------------------
X[1] and Y[1] code two values for comparison, function parameters.
------Solution--------------------
It means that the value of the 1 index of each element of the array is used for comparison, and the following values are labeled Red:
$prodects = Array (' TIR ', ' Tires', 100),
Array (' oil ', ' Oil', 10),
Array (' SPK ', ' Spark Plugs', 4));
------Solution--------------------
function Compare ($x, $y)
{
Var_dump ($x, $y); Look, I know.
The reason for no output is that $products does not exist