(PHP 4, PHP 5)
array_merge — 合并一个或多个数组
array_merge() 将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面。返回作为结果的数组。
如果输入的数组中有相同的字符串键名,则该键名后面的值将覆盖前一个值。然而,如果数组包含数字键名,后面的值将不会覆盖原来的值,而是附加到后面。
如果只给了一个数组并且该数组是数字索引的,则键名会以连续方式重新索引。
例 237. array_merge() 例子
<?php
$array1 = array("color" => "red", 2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge($array1, $array2);
print_r($result);
?>
上例将输出:
Array
(
[color] => green
[0] => 2
[1] => 4
[2] => a
[3] => b
[shape] => trapezoid
[4] => 4
)
例 238. 简单的 array_merge() 例子
<?php
$array1 = array();
$array2 = array(1 => "data");
$result = array_merge($array1, $array2);
?>
别忘了数字键名将会被重新编号!
Array
(
[0] => data
)
如果你想完全保留原有数组并只想新的数组附加到后面,用 + 运算符:
<?php
$array1 = array();
$array2 = array(1 => "data");
$result = $array1 + $array2;
?>
数字键名将被保留从而原来的关联保持不变。
Array
(
[1] => data
)
array_merge() 的行为在 PHP 5 中被修改了。和 PHP 4 不同,array_merge() 现在只接受 array 类型的参数。不过可以用强制转换来合并其它类型。请看下面的例子。
例 239. array_merge() PHP 5 例子
<?php
$beginning = 'foo';
$end = array(1 => 'bar');
$result = array_merge((array)$beginning, (array)$end);
print_r($result);
?>
上例将输出:
Array
(
[0] => foo
[1] => bar
)
参见 array_merge_recursive(),array_combine() 和数组运算符。
http://www.php.net/manual/zh/function.array-merge.php
Zend Optimizer 3.3.0a, http://www.zend.com/products/zend_optimizer
phpMyAdmin 2.11.2, http://www.phpmyadmin.net/home_page/index.php
Zend Core 2.5.0, http://www.zend.com/products/zend_core
Zend Platform 3.0.3, http://www.zend.com/products/zend_platform
PHP 5.2.5, http://www.php.net/releases/5_2_5.php
Zend Studio 5.5, http://www.zend.com/products/zend_studio
Zend Guard 5.0, http://www.zend.com/products/zend_guard
PHP: PHP 类型比较表 - Manual: http://www.php.net/manual/zh/types.comparisons.php#id9240444
PHP: 变量范围 - Manual:, http://www.php.net/manual/zh/language.variables.scope.php#language.variables.scope.references
PHP - PHP 的命令行模式 - CLI 专用常量, http://www.php.net/manual/zh/features.commandline.php#id2715646
PHP - token_get_all用于解析PHP源代码, http://www.php.net/manual/zh/function.token-get-all.php
PHP - reset — 将数组的内部指针指向第一个单元, http://www.php.net/manual/zh/function.reset.php
PHP - serialize — 产生一个可存储的值的表示, http://www.php.net/manual/zh/function.serialize.php
PHP: 魔术常量 - Manual:, http://www.php.net/manual/zh/language.constants.predefined.php
PHP: SOAP Functions - soap.wsdl_cache_enabled, http://cn.php.net/manual/zh/ref.soap.php#ini.soap.wsdl-cache-enabled
字符串转换为数值, http://www.php.net/manual/zh/language.types.string.php#language.types.string.conversion
Class Abstraction类抽象, http://www.php.net/manual/zh/language.oop5.abstract.php
foreach遍历数组, http://www.php.net/manual/zh/control-structures.foreach.phpSOAP configuration options missing documentation文档中丢失SOAP配置选项, http://bugs.php.net/bug.php?id=38644
PHP 的命令行模式, http://www.php.net/manual/zh/features.commandline.php
位运算符, http://www.php.net/manual/zh/language.operators.bitwise.php#id2665181
file_exists检查文件或目录是否存在, http://www.php.net/manual/zh/function.file-exists.php
is_file判断给定文件名是否为一个正常的文件, http://www.php.net/manual/zh/function.is-file.php
settype设置变量的类型, http://cn.php.net/manual/zh/function.settype.php#function.settype
is_numeric检测变量是否为数字或数字字符串, http://www.php.net/manual/zh/function.is-numeric.php
ksort对数组按照键名排序, http://www.php.net/manual/zh/function.ksort.php
概述, http://www.php.net/manual/zh/language.exceptions.php
用异常处理php改进流程
引用返回, http://www.php.net/manual/zh/language.references.return.php
array_merge合并一个或多个数组, http://www.php.net/manual/zh/function.array-merge.php
概述, http://www.php.net/manual/zh/ref.curl.php
curl_setopt设置cURL传输的选项, http://www.php.net/manual/zh/function.curl-setopt.php#function.curl-setoptregister_shutdown_function注册一个脚本结束时调用的函数, http://www.php.net/manual/zh/function.register-shutdown-function.php
sleep延迟执行, http://www.php.net/manual/zh/ref.misc.php
uniqid生成唯一ID, http://www.php.net/manual/zh/function.uniqid.php
mysql_real_escape_string转义SQL语句中使用的字符串中的特殊字符,并考虑到连接的当前字符集, http://www.php.net/manual/zh/function.mysql-real-escape-string.php
proc_open执行命令并打开用于输入输出的文件指针, http://www.php.net/manual/zh/function.proc-open.php
strpos查找一个字符串第一次出现的位置, http://www.php.net/manual/zh/function.strpos.php
substr返回字符串中的一部分, http://www.php.net/manual/zh/function.substr.php
short_open_tag决定是否允许使用PHP代码开始标志的缩写形式, http://www.php.net/manual/zh/ini.core.php#ini.short-open-tag
服务器变量:$_SERVER, http://www.php.net/manual/zh/reserved.variables.php#reserved.variables.server
语法着色, php.exe -s "%1" > "%1.html"
移除SimpleXML对象中的子对象