-1

我得到了这个 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
        )

)
4

2 回答 2

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>';
}

如果您可以打印它,您可以根据需要将其保存到新阵列中。

于 2013-03-01T09:23:25.457 回答
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>";

你应该阅读一些教程。这些是真正的基础。

于 2013-03-01T10:27:02.770 回答