PHP - Manual手册 - V. Array 数组函数 - array_merge合并一个或多个数组
array_merge
(PHP 4, PHP 5)
array_merge — 合并一个或多个数组
说明
array array_merge ( array $array1 [, array $array2 [, array $...]] )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 类型的参数。不过可以用强制转换来合并其它类型。请看下面的例子。
参见 array_merge_recursive(),array_combine() 和数组运算符。
[PHP: array_merge - Manual:]
http://www.php.net/manual/zh/function.array-merge.php
[PHP - 关键词]
php[PHP - 相关论坛]
http://php.board.newsmth.net/ http://bbs.pku.edu.cn/, homepage看版 http://forum.csdn.net/SList/PHP/[PHP - 下载]
AppServ 2.5.9, http://www.appservnetwork.com/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 - Manual手册]
PHP: PHP 类型比较表 - Manual: http://www.php.net/manual/zh/types.comparisons.php#id9240444
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
字符串转换为数值, 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
[PHP - Manual手册 - 下载]
http://www.php.net/download-docs.php[PHP - Manual手册 - 第19章 类与对象(PHP 5)]
Object cloning对象克隆, http://www.php.net/manual/zh/language.oop5.cloning.php[PHP - Manual手册 - 第20章 异常处理]
概述, http://www.php.net/manual/zh/language.exceptions.php
用异常处理php改进流程
[PHP - Manual手册 - 第21章 引用的解释]
引用返回, http://www.php.net/manual/zh/language.references.return.php
[PHP - Manual手册 - V. Array 数组函数]
计算数组的交集, http://www.php.net/manual/zh/function.array-intersect.phparray_merge合并一个或多个数组, http://www.php.net/manual/zh/function.array-merge.php
[PHP - Manual手册 - XVIII. CURL, 客户端URL库函数]
概述, http://www.php.net/manual/zh/ref.curl.php
curl_setopt设置cURL传输的选项, http://www.php.net/manual/zh/function.curl-setopt.php#function.curl-setopt[PHP - Manual手册 - XXII. Date/Time 日期/时间函数]
date格式化一个本地时间/日期, http://www.php.net/manual/zh/function.date.php[PHP - Manual手册 - XXXIII. Error Handling and Logging Functions错误处理和日志函数]
概述, http://www.php.net/manual/zh/ref.errorfunc.php[PHP - Manual手册 - XLVII. Function Handling Functions函数管理函数]
[PHP - Manual手册 - XC. Miscellaneous Functions杂项函数]
sleep延迟执行, http://www.php.net/manual/zh/ref.misc.php
uniqid生成唯一ID, http://www.php.net/manual/zh/function.uniqid.php
[PHP - Manual手册 - XCVIII. MySQL 函数]
[PHP - Manual手册 - CXXVII. PostgreSQL 数据库函数]
pg_insert将数组插入到表中, http://www.php.net/manual/zh/index.php[PHP - Manual手册 - CXXX. Program Execution Functions程序调用函数]
proc_open执行命令并打开用于输入输出的文件指针, http://www.php.net/manual/zh/function.proc-open.php
[PHP - Manual手册 - CXLIX. Session 会话处理函数]
session.save_path 定义了传递给存储处理器的参数, http://www.php.net/manual/zh/ref.session.php#ini.session.save-path[PHP - Manual手册 - CLXI. String 字符串处理函数]
str_pad使用另一个字符串将一个字符串填充到指定长度, http://www.php.net/manual/zh/function.str-pad.phpstrpos查找一个字符串第一次出现的位置, http://www.php.net/manual/zh/function.strpos.php
substr返回字符串中的一部分, http://www.php.net/manual/zh/function.substr.php
[PHP - Manual手册 - CLXVI. Tidy Functions - Tidy函数]
概述, http://www.php.net/manual/zh/ref.tidy.php[PHP - Manual手册 - CLXIX. URL 函数]
概述, http://www.php.net/manual/zh/ref.url.php[PHP - Manual手册 - 附录 H. php.ini 配置选项]
register_globals决定是否将 EGPCS(Environment,GET,POST,Cookie,Server)变量注册为全局变量, http://www.php.net/manual/zh/ini.core.php#ini.register-globalsshort_open_tag决定是否允许使用PHP代码开始标志的缩写形式, http://www.php.net/manual/zh/ini.core.php#ini.short-open-tag
[PHP - Manual手册 - 附录 L. 保留字列表]
服务器变量:$_SERVER, http://www.php.net/manual/zh/reserved.variables.php#reserved.variables.server
[PHP - 应用实例]
语法着色, php.exe -s "%1" > "%1.html"
移除SimpleXML对象中的子对象