开发者

Get value from JSON object

开发者 https://www.devze.com 2023-02-12 02:45 出处:网络
stdClass Object ( [form] => stdClass Object ( [fieldsets] => Array ( [0] => stdClass Object ( [fieldset_name] => name_1
stdClass Object
(
    [form] => stdClass Object
        (
            [fieldsets] => Array
                (
                    [0] => stdClass Object
                        (
                            [fieldset_name] => name_1
                            [datapoints] => Array
                                (
              开发者_开发技巧                      [0] => stdClass Object
                                        (
                                            [dp_id] => 4
                                        )

                                    [1] => stdClass Object
                                        (
                                            [dp_id] => 5
                                        )
                                )

                        )

                    [1] => stdClass Object
                        (
                            [fieldset_name] => name_2
                            [datapoints] => Array
                                (
                                    [0] => stdClass Object
                                        (
                                            [dp_id] => 1
                                        )

                                    [1] => stdClass Object
                                        (
                                            [dp_id] => 3
                                        )

                                )

                        )

                )

        )

)

Now i want the values of dp_id seperately into two arrays ie.,array(4,5) and array(1,3)


foreach($object->form->fieldsets as $fieldset) {
    $dp_ids = array();
    foreach($fieldset->datapoints as $datapoint)
        $dp_ids[] = $datapoint->dp_id;
    var_dump($dp_ids);
}


try this.

$object->form['fieldsets'][1]->datapoints[1]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号