Home >Backend Development >PHP Tutorial >PHP method to merge associative and non-associative arrays through array_merge() function_PHP tutorial

PHP method to merge associative and non-associative arrays through array_merge() function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:02:32958browse

How PHP merges associative and non-associative arrays through the array_merge() function

This article mainly introduces how PHP merges associative and non-associative arrays through the array_merge() function. Involving the array_merge() function operation array merging skills in php, friends who need it can refer to it

The example in this article describes how PHP merges associative and non-associative arrays through the array_merge() function. Share it with everyone for your reference. The specific analysis is as follows:

array_merge() is a php function used to merge arrays. The latter array is appended to the end position of the previous one and returns the merged result array.

?

1

2

3

4

5

6

$beginning = 'foo';

$end = array(1 => 'bar');

$result = array_merge((array)$beginning, (array)$end);

print_r($result);

?>

1 2

3

4

5

6

1

2

3

4

5

Array

(

[0] => foo

[1] => bar

)

$beginning = 'foo';

$end = array(1 => 'bar'); $result = array_merge((array)$beginning, (array)$end);

print_r($result);?>
The output results are as follows:
?
1
2 3 4 5
Array ( [0] => foo [1] => bar )
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/969961.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969961.htmlTechArticlephp method of merging associative and non-associative arrays through the array_merge() function. This article mainly introduces how php uses the array_merge() function. ) Function method to merge associative and non-associative arrays, involving array in php...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn