Calling array_merge()
with all the arrays as parameters will return the joined array. Keep in mind, however, that same-valued keys will be overwritten.
How to get thease object array to single array
문제
Please help to sort out below...
I need to get following kind of a array in to a single array in PHP
Thanks
Array
(
[0] => stdClass Object
(
[title]=>name1
)
)
Array
(
[0] => stdClass Object
(
[title]=>name2
)
)
Array
(
[0] => stdClass Object
(
[title]=>name3
)
)
this array in to
Array
(
[0] => stdClass Object
(
[title]=>name1
)
[1] => stdClass Object
(
[title]=>name2
)
[2] => stdClass Object
(
[title]=>name3
)
)
해결책
다른 팁
array_merge()
is Merge arrays into one array:
for eg:-
<?php
$a1=array("a"=>"red","b"=>"green");
$a2=array("c"=>"blue","b"=>"yellow");
print_r(array_merge($a1,$a2));
?>
Try with array_merge
like
$new_arr = array_merge($arr1,$arr2,$arr3);
Or like
$arr4 = array_merge($arr1,$arr2);
$new_arr = array_merge($arr4,$arr3);
Please try this code, may be it will help you.
$x = (object) array(array('title'=>'name1'));
$y = (object) array(array('title'=>'name2'));
//both arrays will be merged including duplicates
$arry1 = (array)$x;
$arry2 = (array)$y;
$result = array_merge($arry1, $arry2 );
$result = array_map("unserialize", array_unique(array_map("serialize", $result)));
$result = (object)$result;
제휴하지 않습니다 StackOverflow