简体   繁体   中英

how to Append an arrays values and keys to another array in PHP

IN PHP i have the following arrays.

阵列1

And i have this array:

阵列2

What i want to do is append the second array to the first one, i tried doing it like so:

end($array1);
 foreach($array2 as $key => $value ){
 $array1[$key] = $value;

 }

With this result:

新阵列

My question is; How do i put the the values and keys of the second array into the first one?

Answer: due to the answer of Manikiran i now got the following array as a result:

解

array_merge() is the function you are looking for. Try the following code:

$new_array=array_merge($array1,$array2);

For more information, check out the manual

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM