I want to merge an array
like first element to an object
like second element. Is it possible to merge a php object and a php array? If so, How do I merge these?
I have snipped via print_r
First Element (array)
Array
(
[start_date] => 2014-12-28
)
Second Element (object)
Bannerlookup Object
(
[_new:CActiveRecord:private] =>
[_attributes:CActiveRecord:private] => Array
(
[id] => 1
[name] => First Banner
[description] => My first banner description goes here
[type] => 1
[position] => 1
[price] => 20
[status] => 1
)
[_related:CActiveRecord:private] => Array
(
)
[_c:CActiveRecord:private] =>
[_pk:CActiveRecord:private] => 1
[_alias:CActiveRecord:private] => t
[_errors:CModel:private] => Array
(
)
[_validators:CModel:private] =>
[_scenario:CModel:private] => update
[_e:CComponent:private] =>
[_m:CComponent:private] =>
)
Thanks in advance :)
First convert the object to array.
$new_array = json_decode(json_encode($your_object), true);
Now merge it with the existing array.
$merged_array = array_merge( $old_array, $new_array) ;
merging will cause the same key
override by the second array. See Array Merge Manual
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다