2015-09-10 95 views
0

我得到下面這個數組更改陣列格式PHP

Array 
(
    [product_id] => ? 
    [sku] => testsku 
    [type] => simple 
    [created_at] => ? 
    [updated_at] => ? 
    [type_id] => ? 
    [name] => newproduct 
    [description] => newproduct 
    [short_description] => newproduct 
    [weight] => 1 
    [status] => 1 
    [url_key] => newproduct.html 
    [url_path] => newproduct 
    [visibility] => 4 
    [has_options] => ? 
    [gift_message_available] => ? 
    [price] => 15 
    [special_price] => ? 
    [special_from_date] => ? 
    [special_to_date] => ? 
    [tax_class_id] => 4 
    [meta_title] => ? 
    [meta_keyword] => ? 
    [meta_description] => ? 
    [custom_design] => ? 
    [custom_layout_update] => ? 
    [options_container] => ? 
    [websitre_id] => ? 
    [attribute_set_id] => ? 
    [simples_skus] => ? 
    [re_skus] => ? 
    [configurable_attributes] => ? 
    [color] => ? 
) 

的要求是不同的。我用

$陣列= json_decode(json_encode($數據),真)

基本上,我是通過調用Magento的SOAP服務得到這個數組,並希望將此數組轉換爲完全一樣:

$data = array(0 => array(
     'name' => 'newproduct55445', 
     'sku' => 'mynewsku1', 
     'description' => 'Product description', 
     'short_description' => 'Product short description', 
     'weight' => '10', 
     'status' => '1', 
     'url_key' => 'newproduct', 
     'url_path' => 'newproduct.html', 
     'visibility' => '4', 
     'price' => '100', 
     'tax_class_id' => 1, 
     'meta_title' => 'Product meta title', 
     'meta_keyword' => 'Product meta keyword', 
     'meta_description' => 'Product meta description', 
     'store' => 'admin', 
     'attribute_set' => 'default', 
     'type' => 'configurable', 
     'tax_class_id' => 4, 
     'status' => 1, 
     'visibility' => 4, 
     'is_in_stock' => 1, 
     'simples_skus' => 'myproduct' 
     )); 
+0

你可以操縱,使用的foreach – aldrin27

回答

0

你可以做這樣的方式:

$array = array(); 
$array[] = json_decode(json_encode($data), true); 
+0

我無法將[product_id]轉換爲'product_id' – Rohit