Question

It works fine in localhost, but when I upload, it shows Parse Error. Can you figure out my error?

My PHP Function:

function all_fuel_info(){
global $conx;
$sql = "SELECT `qty`,`cost`,`rate` FROM `fuel_order`;";
$query = mysqli_query($conx, $sql);
$liters = 0; $cost = 0;
while ($row = mysqli_fetch_array($query)){
    $liters += $row["qty"];
    $cost += $row["cost"];
}
$info = array('qty' => $liters, 'cost' => $cost);
return $info;

}

Then the PHP Code:

  $total = all_fuel_info()["cost"];

Is this not supported in PHP? According to my knowledge yet, I can point to that item of the array using the index. Am I wrong?

Was it helpful?

Solution

This syntax isn't supported until PHP 5.4. Your server is likely running an older version.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top