This is the json array I have and I decode it using json_decode() of php
{"form":{"fieldsets":[{"fieldset_name":"name_1","datapoints":{"dp_id_1":1,"dp_id_2":4}},{"fieldset_name":"name_2","datapoints":{"dp_id_3":1,"dp_id_4":5}}]}}.
After decoding the array I obtained is
Array (
[form] => Array (
[fieldsets] => Array (
[0] => Array (
[fieldset_name] => name_1
[datapoints] => Array (
[dp_id_1] => 1
[dp_id_2] => 4
)
)
开发者_开发技巧 [1] => Array (
[fieldset_name] => name_2
[datapoints] => Array (
[dp_id_3] => 1
[dp_id_4] => 5
)
)
)
)
)
Now I want to push datapoints array dp_id_1,dp_id_2 elements into one array and dp_id_3,dp_id_4 into other array
Please help me........
Simply loop over the array:
$points = array();
for($array['form']['fieldsets'] as $set) {
$points = array_merge($points, $set['datapoints']);
}
Update:
Regarding your edit, then it is even simpler. Replace the body with:
$points[] = $set['datapoints'];
I suggest to read about arrays in PHP to get a better understanding on how they work.
精彩评论