I am fairly new to PHP. I have a function which checks the cost of price. I want to return the variable from this function to be used globally:
functio
As some alrady said, try using classes for this.
class myClass
{
private $delivery_price;
public function setDeliveryPrice($qew = 0)
{
if ($qew == "1") {
$this->delivery_price = "60";
} else {
$this->delivery_price = "20";
}
}
public function getDeliveryPrice()
{
return $this->delivery_price;
}
}
Now, to use it, just initialize the class and do what you need:
$myClass = new myClass();
$myClass->setDeliveryPrice(1);
echo $myClass->getDeliveryPrice();