php - How to insert value key-value pair in array -
i'm trying insert value key pair in array in php. code given below issue is giving error illegal offset type on line i'm trying push data. $request_url data coming api.
$response = simplexml_load_file($request_url); //make different array of images of small , medium , large size $array_features = array(); $array_smallimages = array(); $array_mediumimage = array(); $array_largeimage = array(); foreach($response->items->item $item){ echo $item->itemattributes->title.'<br>'; echo $item->asin.'<br>'; $asin = $item->asin; echo $item->detailpageurl.'<br>'; echo $item->itemattributes->manufacturer.'<br>'; $small_img = $item->smallimage->url; $array_smallimages[$asin] = $small_img; //$array_smallimages = $item->smallimage->url; echo $item->mediumimage->url.'<br>'; echo $item->largeimage->url.'<br>'; //echo $item->itemattributes->manufacturer.'<br>'; echo 'features:'.'<br>'; foreach($item->itemattributes->feature $fea){ // $array_features[$item->asin] = $fea; echo $fea.'<br>'; }
$array_smallimages[$asin] = $small_img; line on error coming warning: illegal offset type
illegal offset type errors occur when attempt access array index using object or array index key
use trim($asin)
before $array_smallimages[$asin] = $small_img;
Comments
Post a Comment