php - Cannot set object value with merge value

263

I have a a problem with my loop. When Iprint_r($item); on key 'text' value only show$item->NamaUnor value, not$item->NamaPim too. This is my code:

foreach($items as $item){
    $item->text=&$item->NamaUnor.' '.$item->NamaPim;
    $item->href=&$item->KdUnor;

    $childs[$item->UnorAtasan][] = $item;

    unset($item->NamaPim,$item->NamaUnor,$item->UnorAtasan);
}
225

Answer

Solution:

thanks all i was fix it with add & before $item to foreach on my code.

foreach($items as **&$item**){
$item->text=&$item->NamaUnor.' '.$item->NamaPim;
$item->href=&$item->KdUnor;

$childs[$item->UnorAtasan][] = $item;

unset($item->NamaPim,$item->NamaUnor,$item->UnorAtasan);

}

People are also looking for solutions to the problem: php - Query doesn't work on my Raspberry Pi 2B

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.