-3

我有一个这样的数组:

数组 ( [0] => stdClass Object ( [id] => 1 [title] => ABC [sentece] => blablabla... [topic] => Science ) [1] => stdClass Object ( [id] = > 2 [title] => DEF [sentence] => nomnomnom... [topic] => 技术)

如何在 php 的 stdClass 对象中添加一个数组?

例如:我想添加这个数组:

$number = array (82, 61);

所以,我会有这个数组:

Array ( [0] => stdClass Object ( [id] => 1 [title] => ABC [sentece] => blablabla... [topic] => Science [number] => 82 ) [1] => stdClass对象 ( [id] => 2 [title] => DEF [sentece] => nomnomnom... [topic] => 技术 [number] => 61

)

谢谢你的帮助。

4

1 回答 1

0

使用您提供的信息,您需要手动执行此操作。

手动输入

$Array = [
    //your array
];
$Array[0]->number = 82;
$Array[1]->number = 61;

自动化?

$Array = [
    //your array
];
$Numbers = [82, 61];
foreach($Numbers as $key => $number) {
    if(isset($Array[$key]) {
        $Array[$key]->number = $number;
    }
}
于 2013-05-09T10:09:40.853 回答