문제

I have an stdClass Object like generated by joomla like this

$db->setQuery($sql);
$schoollist = $db->loadObjectList(); 

And the $schoollist variable contains the following stdClass Objects

stdClass Object ( [id] => 1 [col1] => blabla [col2] => 5 [col3] => 208 ) 
stdClass Object ( [id] => 2 [col1] => test1 [col2] => 1 [col3] => 52 ) 

and I need to add another "column" after the query as [col4] => dsdads , so the result will be like this

stdClass Object ( [id] => 1 [col1] => blabla [col2] => 5 [col3] => 208 [col4] => 208) 
stdClass Object ( [id] => 2 [col1] => test1 [col2] => 1 [col3] => 52 [col4] => 208) 

how can I do this?

도움이 되었습니까?

해결책

Simply set a new field:

$object->col4 = $value;

If you need dynamic field names:

$object->$fieldName = $value;

다른 팁

RE dynamic field names.

These should be defined as such.

$object->{$fieldName} = $value;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top