【问题标题】:Change array format PHP更改数组格式 PHP
【发布时间】:2015-09-10 07:01:15
【问题描述】:

我得到以下数组

    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] => ?
)

要求不同。我用过

$array = json_decode(json_encode($data), true)

基本上,我通过调用 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'
        ));

【问题讨论】:

  • 您可以使用 foreach 进行操作

标签: php arrays magento soap soap-client


【解决方案1】:

你可以这样做:

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

【讨论】:

  • 我无法将 [product_id] 转换为 'product_id'
猜你喜欢
  • 2011-09-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-18
相关资源
最近更新 更多