【问题标题】:How to map array?如何映射数组?
【发布时间】:2021-06-23 07:57:00
【问题描述】:

我有这样的 json 数组对象

[0] => stdClass Object
        (
            [uniqID_Customer] => Cust-9a8a34e1
            [nama_customer] => abc
            [address] => Array
                (
                    [0] => stdClass Object
                        (
                            [id_customers] => Cust-9a8a34e1
                            [address] => new york
                        )
                )
        )

如何从多维数组生成单个数组

可以这样

[0] => stdClass Object
        (
            [uniqID_Customer] => Cust-9a8a34e1
            [nama_customer] => abc
            [address] => new york
        )

【问题讨论】:

  • 欢迎来到 SO ... codeigniter 与 Laravel 有什么关系?
  • 在使用 codeigniter 之前我是 laravel 新手
  • 这可以通过一个比较简单的循环来实现。你试过写什么吗?如果你有,请分享你的努力并解释它在哪里以及如何未能满足你的需要。
  • 我只是使用这个 json_decode(json_encode( eloCust::with('eloAdr','eloCustImg')->where('uniqID_Customer',$id)->get()->->toArray ()),假);

标签: php arrays mapping


【解决方案1】:

类似:

$jsonArray[0]->address = $jsonArray[0]->address[0]->address;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-31
    • 2013-07-17
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多