如何添加新的 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] => 
)

正如你在里面看到的,对象必须是[可流式传输]的另一个对象,所以我真的不知道该怎么做,所以我希望有人可以帮助我。

谢谢

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

通常它们是这样添加的:

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