Answer the question
In order to leave comments, you need to log in
Why is the value of the object being reset?
There are sl. the code:
$adverts = DB::select('id', 'rate')
->from(ORM::factory('Advert')->table_name())
->as_object('Advert')->execute();
foreach ($adverts as $advert){
$advert->rate = rand(0,10);
var_dump($advert->rate);
}
foreach ($adverts as $advert)
var_dump($advert->rate);
float(5)
NULL
$advert->rate
?
Answer the question
In order to leave comments, you need to log in
// в $advert - копия элемента $adverts, изменения в ней не отражаются на самом массиве
foreach ($adverts as $advert) { }
// в $advert - ссылка на элемент $adverts, изменения в ней - это изменения в самом массиве
foreach ($adverts as &$advert) { }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question