在 for 循环中,我正在合并数组,但在循环末尾只添加最后一个。
$result = json_decode($response['body']);
if(isset($result->{'items'})) {
$count = count($result->{'items'});
} else {
$count = 0;
}
$json = [];
if($count > 0) {
for ($i=0; $i < $count; $i++) {
if (isset($result->{'items'}[$i]->{'title'})) {
$title = $result->{'items'}[$i]->{'title'};
$title_array = array('title' => $title);
$json = array_merge($json, $title_array);
}
}
}
杨__羊羊
智慧大石