我得到这个std类对象数组如何在单个数组中调用它,因为你只能看到一些值被更改。
Array
(
[0] => stdClass Object
(
[movie_id] => 4
[movie_name] => Harvey
[genre_id] => 4
[genre_title] => Action/Adventure
[rating_id] => 2
[rating_title] => Pg-16 (USA)
[person_id] => 14
[person_name] => John Beck
[role_title] => producer
)
[1] => stdClass Object
(
[movie_id] => 4
[movie_name] => Harvey
[genre_id] => 4
[genre_title] => Action/Adventure
[rating_id] => 2
[rating_title] => Pg-16 (USA)
[person_id] => 15
[person_name] => Henry Koster
[role_title] => directer
)
[2] => stdClass Object
(
[movie_id] => 4
[movie_name] => Harvey
[genre_id] => 4
[genre_title] => Action/Adventure
[rating_id] => 2
[rating_title] => Pg-16 (USA)
[person_id] => 16
[person_name] => Mary Coyle Chase
[role_title] => writer
)
[3] => stdClass Object
(
[movie_id] => 4
[movie_name] => Harvey
[genre_id] => 4
[genre_title] => Action/Adventure
[rating_id] => 2
[rating_title] => Pg-16 (USA)
[person_id] => 17
[person_name] => Oscar Brodney
[role_title] => writer
)
[4] => stdClass Object
(
[movie_id] => 4
[movie_name] => Harvey
[genre_id] => 4
[genre_title] => Action/Adventure
[rating_id] => 2
[rating_title] => Pg-16 (USA)
[person_id] => 18
[person_name] => Myles Connolly
[role_title] => writer
)
)
答案 0 :(得分:1)
不太确定你想要实现的目标。要仅打印某些成员,请尝试执行以下操作:
foreach ($your_array as $key => $value) {
echo '<pre>';
echo $value->person_id . " ";
echo $value->person_name . " ";
echo $value->role_title . " ";
echo "\n";
echo '</pre>';
}
如果您可以打印它,您可以根据需要将其保存到新阵列。
答案 1 :(得分:0)
这就是你想要的:
echo '<pre>';
foreach ($arr as $key => $value) {
$newarray[$key]["person_id"] = $value->person_id;
$newarray[$key]["person_name"] = $value->person_name;
$newarray[$key]["role_title"] = $value->role_title;
}
// var_dump($newarray);
$json = json_encode($newarray);
echo $json;
echo "</pre>";
你应该阅读一些教程。这些是真正的基础。