Assigned variable empty outside of switch statement PHP -
public function store($feed) { switch($feed) { case 'full': $coupons = json_decode(file_get_contents('path-to-json-feed'), true); break; case 'incremental': $coupons = json_decode(file_get_contents('path-to-different-json-feed'), true); break; } var_dump($coupons);die(); $this->deal_model->updatealldeals($coupons); echo 'coupons updated'; }
i trying assign value $coupons
var_dump($coupons)
returns empty array.
i'd suggest add default
, in case $feed
other full
or incremental
.
if actual code, not sure if there file called path-to-json-feed
, seems should else, actual path json file/feed.
replace path-to-json-feed
actual file, , try below code , see get.
public function store($feed) { switch($feed) { case 'full': $coupons = json_decode(file_get_contents('path-to-json-feed'), true); break; case 'incremental': $coupons = json_decode(file_get_contents('path-to-json-feed'), true); break; default: $coupons = json_decode(file_get_contents('path-to-json-feed'), true); break; } var_dump($coupons); die(); // debugging $this->deal_model->updatealldeals($coupons); echo 'coupons updated'; }
Comments
Post a Comment