我真的很困惑。通常我使用数组推送将新数据添加到数组中。但它不起作用。有人能帮助我吗?
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]的另一个对象,所以我真的不知道该怎么做,所以我希望有人可以帮助我。
由于
答案 0 :(得分:0)
我会不惜一切代价避免在数组中混合对象以避免以后的头痛。
通常这就是它们的添加方式:
$oData = new stdClass;
$oData->name = 'Bob';
$oData->email = 'Bob@bob.com';
$aArray = array();
$aArray[] = $oData;
var_dump( $aArray );