How to iterate this PHP array using foreach -


i use code data api in form of array:

$getcurrentstock = $myapi->getcurrentstock('array');  print_r($getcurrentstock); 

i getting data in form of array this:

array ( [status] => ok [returnval] => array ( [0] => array ( [name] => alcatel [model] => hero ot-8020x [color] => black [warehouse] => hu11 [bar_code] => a20200125 [in_stock] => <20 [exp_delivery] => 0 [exp_available] => <20 [delivery_date] => - [price] => 301.90 [properties] => array ( [eu_warranty] => no [keypad] => touch screen [manual] => hun [simlock] => sim free [remarks] => data cable, headset [language] => ger, eng, esp, fra, ita, hun, ned, por, rom, tur [country] => china ) [ean] => [image] => http://www.mobileshop.bz/phone-pictures/api/3531-alcatel-hero-ot-8020x.jpg [id] => 3531 [category] => mobile ) [1] => array ( [name] => alcatel [model] => idol 2 mini ot-6016x [color] => gray [warehouse] => hu11 [bar_code] => a20200121 [in_stock] => <5 [exp_delivery] => 0 [exp_available] => <5 [delivery_date] => - [price] => 192.60 [properties] => array ( [eu_warranty] => no [keypad] => touch screen [manual] => hun [simlock] => sim free [remarks] => data cable, headset [language] => cat, ger, eng, esp, fra, ita, hun, ned, por, rom, tur [country] => china ) [ean] => [image] => http://www.mobileshop.bz/phone-pictures/api/3345-alcatel-idol-2-mini-ot-6016x.jpg [id] => 3345 [category] => mobile ) [2] => array ( [name] => alcatel [model] => idol 2 mini ot-6016x [color] => white [warehouse] => hu11 [bar_code] => a20200120 [in_stock] => <5 [exp_delivery] => 0 [exp_available] => <5 [delivery_date] => - [price] => 192.60 [properties] => array ( [eu_warranty] => no [keypad] => touch screen [manual] => hun [simlock] => sim free [remarks] => data cable, headset [language] => cat, ger, eng, esp, fra, ita, hun, ned, por, rom, tur [country] => china ) [ean] => [image] => http://www.mobileshop.bz/phone-pictures/api/3346-alcatel-idol-2-mini-ot-6016x.jpg [id] => 3346 

i have add each product data programmatically database. single product added this:

 $productdata = array(         'product_description' => array('1' => array('name' => 'alcatel', 'meta_description' => '' ,'meta_keyword' =>'', 'description' => '', 'tag' =>'')),          'model' => 'alcatel hero ot-8020x black',         'price' => '301.40',          'tax_class_id' => 0,         'quantity' => 1,         'minimum' => 1,         'subtract' => 1,         'stock_status_id' => 6,         'shipping' => 1 ,         'image' => 'http://www.mobileshop.bz/phone-pictures/api/3531-alcatel-hero-ot-8020x.jpg',         'manufacturer' => 'alcatel',         'manufacturer_id' => 44,         'category' => 'ce',         'product_category' => array('0' => 61),         'product_store' => array('0' => 0),         'date_available' => '2015-03-31',         'length_class_id' => 1,         'weight_class_id' => 1,         'status' => 1,         'sort_order' => 1,          );      //load model     $this->load->model('catalog/product');      // attempt pass assoc array add product method     $this->model_catalog_product->addproduct($productdata); 

how add product in bulk programmatically using foreach?

you can create foreach loop records have got.

$this->load->model('catalog/product');  foreach($getcurrentstock['returnval'] $value){     $productdata = array(         'model' => $value['model'],         'price' => $value['price'],     );    // add other values in above array    $this->model_catalog_product->addproduct($productdata); }  

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -