I have an array say $packages. I have the code like this to prevent the undefined variable error.
$hospital_charge=0;
if(!empty($packages)){
foreach($packages as $package){
$hospital_charge=$package['hospital_charge'];
Then in subsequent code I use
$health_card_discount = ((($a*5)/100)+($hospital_charge*.05));
That is if $hospital_charge have a null value, I get the error
undefined variable hospital_charge,
so to prevent that I defined $hospital_charge=0
is this the proper way of doing it or there is better way of achieving this?
Note:I am using PHP 5.4.16
isset().