PHP array_merge merge and split two arrays_PHP tutorial
WBOY
Release: 2016-07-13 17:14:09
Original
1154 people have browsed it
I was confused about the array_merge function and + operator of arrays, so I wrote a small program to compare them and found their differences.
Especially the + operator, which means to append the right array unit (to remove duplicates) to the left array.
第二种情况
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
[6] => a
[7] => x
[8] => y
)
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
)
Array
(
[0] => a
[1] => x
[2] => y
[3] => d
[4] => e
[5] => f
)
第三种情况
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
[6] => a
[7] => x
[8] => y
)
Array
(
[1] => a
[2] => b
[3] => c
[4] => d
[5] => e
[6] => f
[7] => x
[8] => y
)
Array
(
[1] => a
[7] => x
[8] => y
[2] => b
[3] => c
[4] => d
[5] => e
[6] => f
)
第二种情况
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
[6] => a
[7] => x
[8] => y
)
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
)
Array
(
[0] => a
[1] => x
[2] => y
[3] => d
[4] => e
[5] => f
)
第三种情况
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
[6] => a
[7] => x
[8] => y
)
Array
(
[1] => a
[2] => b
[3] => c
[4] => d
[5] => e
[6] => f
[7] => x
[8] => y
)
Array
(
[1] => a
[7] => x
[8] => y
[2] => b
[3] => c
[4] => d
[5] => e
[6] => f
)
Split array array_slice()
The array_slice() function will return a portion of the array, starting from the key offset and ending at offset+length. Its form:
Php code
1.array array_slice (array array, int offset[,int length])
array array_slice (array array, int offset[,int length])
When offset is a positive value, splitting will start at offset from the beginning of the array; if offset is negative, splitting will start at offset from the end of the array. If the optional length parameter is omitted, the split will start at offset and go to the last element of the array. If length is given and is positive, it ends at offset+length from the beginning of the array. Conversely, if length is given and is negative, it ends at count(input_array)-|length| from the beginning of the array. Consider an example:
<🎜>//output<🎜>
// Array ( [0] => Orange [1] => Pear [2] => Grape )
?>
http://www.bkjia.com/PHPjc/629036.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629036.htmlTechArticleI was confused about the array_merge function and the + operator of arrays, so I wrote a small program to compare and found their differences. . Especially the + operator, what he means is to remove the duplication of the array unit on the right...
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