문제

I have an array like this:

Array ( [0] => stdClass Object ( [id] => 1 [title] => ABC [sentece] => blablabla... [topic] => Science ) [1] => stdClass Object ( [id] => 2 [title] => DEF [sentece] => nomnomnom... [topic] => Technology )

How to add an array in stdClass Object in php?

For example: I want to add this array:

$number = array (82, 61);

So, I will have this array:

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

)

Thanks for your help.

도움이 되었습니까?

해결책

With the information you provided, you'll need to do that manually.

Manual Entry

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

Automated?

$Array = [
    //your array
];
$Numbers = [82, 61];
foreach($Numbers as $key => $number) {
    if(isset($Array[$key]) {
        $Array[$key]->number = $number;
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top