أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
I have this Array I wanna compaine it to one array using PHP Array ( [0] => Array ( [choices] => Array ( [choices_1] =>1 [choices_2] =>1 ) ) [1] => Array ( [choices] => Array ( [choices_3] =>2 ) ) ) It Should be like this Array ( [choices_1] =>5 [choices_2] =>5 [choices_3] =>2 )
give this a try
$array = Array (0=>Array("choices"=>Array("choices_1"=>1,"choices_2" =>1)),
1 => Array ( "choices" => Array ( "choices_3" =>2)));
$results = array_merge_recursive($array[0],$array[1]);
echo "<pre>";
print_r($results);
echo "</pre>";
You can use array_merge()
$result = array_merge($array1, $array2);
array_merge_recursive($array1, $array2);The above function will do your job. For full reference click
Here. Thanks.
$array = Array (
0=>Array(
"choices"=>Array("choices_1"=>1,"choices_2" =>1)
),
1 => Array ( "choices" => Array ( "choices_3" =>2))
);
$result=array();
foreach($array as $arr){
$result = array_merge($arr['choices'],$result);
}
You can use array_merge()
It is simple in use.
By using array_merge funtion
<?php
$array1 = array("color" => "red", 2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge($array1, $array2);
print_r($result);
?>
use array_merge() function
You can use array_merge function to merge on one or more array to a single array. e.g
Suppose you have2 array array_1 and array_2.
result=array_merge(array_1,array_2).
the resulting array which is in my case is result will contain your all arrays.
<?PHP $your_array=Array(Array('choices'=> Array('choices_1'=>1,'choices_2'=>1)),Array('choices' => Array('choices_3' =>2))); $result = array_merge($your_array[0]['choices'], $your_array[1]['choices']); var_dump($result);?>
array_merge is the way to go.
هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟