I want to use an array and after some calculation make a single element array and then marge these arrays.
like this
$array1[] = array('a'=1 , 'b'=4);
$array2[] array('c'=5);
result[] = array('a'=1 , 'b'=4 , 'c'=5);
开发者_JAVA技巧i need a function in php to do this for me tnx,
All you need is array_merge()
. Read the documentation.
The code you've pasted is not PHP code. Either way, you're probably looking for array_merge
.
use array_merge
$array1 = array('a'=1, 'b'=4); // $array1[] is wrong, it appends to array1
$array2 = array('c'=5);
$result = array_merge($array1, $array2);
This is a joke?
$array1 = array('a' => 1 , 'b' => 4);
$array2 = array('c' => 5);
$result = array_merge($array1, $array2);
Don't know, if your arrays really should look like this
$result[] = array_merge($array1[0], $array2[0]);
Update: The above may be obsolete, the question were changed
However, I guess, that you want something like this
$array1 = array('a'=1 , 'b'=4);
$array2 = array('c'=5);
$result = array_merge($array1, $array2);
array_merge()
$result=array_merge($arr1,$arr2);
精彩评论