如何添加新的 stdClass 对象

How to add new stdClass Object

我真的很困惑。通常我使用数组推送将新数据添加到数组。但这在自动取款机上不起作用。有人可以帮助我吗?

Array
(
[0] => stdClass Object
    (
        [name] => Knijn zijn
        [artist] => Bertie Lukano
        [url] => http://www.last.fm/music/Bertie+Lukano/_/Knijn+zijn
        [streamable] => stdClass Object
            (
                [text] => 0
                [fulltrack] => 0
            )

        [listeners] => 1
        [mbid] => 
    )

[1] => stdClass Object
    (
        [name] => knijnzijn
        [artist] => Bertie Lukano
        [url] => http://www.last.fm/music/Bertie+Lukano/_/knijnzijn
        [streamable] => stdClass Object
            (
                [text] => 0
                [fulltrack] => 0
            )

        [listeners] => 1
        [mbid] => 
    )

[2] => stdClass Object
    (
        [name] => Wij Vieren Feest
        [artist] => Bertie Lukano
        [url] => http://www.last.fm/music/Bertie+Lukano/_/Wij+Vieren+Feest
        [streamable] => stdClass Object
            (
                [text] => 0
                [fulltrack] => 0
            )

        [listeners] => 1
        [mbid] => 
    )

[3] => stdClass Object
    (
        [name] => Hieper de piep ik heb de mexicaanse griep!
        [artist] => Bertie Lukano
        [url] => http://www.last.fm/music/Bertie+Lukano/_/Hieper+de+piep+ik+heb+de+mexicaanse+griep!
        [streamable] => stdClass Object
            (
                [text] => 0
                [fulltrack] => 0
            )

        [listeners] => 1
        [mbid] => 
    )

)

所以我需要添加一个新的 stdClass 对象,但我不知道如何添加。

[4] => stdClass Object
(
    [name] => name
    [artist] => artist
    [url] => url
    [streamable] => stdClass Object
        (
            [text] => 0
            [fulltrack] => 0
        )

    [listeners] => 1
    [mbid] => 
)

如您所见,对象内部需要成为 [streamable] 中的另一个对象,所以我真的不知道该怎么做,希望有人能帮助我。

谢谢

我会不惜一切代价避免在数组中混合对象,以免您以后头疼。

通常是这样添加的:

$oData = new stdClass;
$oData->name  = 'Bob';
$oData->email = 'Bob@bob.com';
$aArray = array();
$aArray[] = $oData;
var_dump( $aArray );