Home php教程 php手册 介绍几个array库的新函数

介绍几个array库的新函数

Jun 13, 2016 am 11:16 AM
array php introduce several function Library us new function of material

 

我们手头的PHP资料不多,大家是不是都有一份php4gb.chm。我最欣赏它里面的函数库部分了,真正的在线帮助。但是PHP发展的脚步实在太快了,你睢,我最近在www.php.net/manual/ 又找到了一些扩展的数组函数。

下面我把它们介绍给大家吧,我的英文水平不高,有译的不对的地方,请指正。
格式是这样的:

函数名 支持版本

函数声明
说明及参数、返回值

例子


OK,Let's go.

//*************************
array_flip (PHP4 >= 4.0b4)

array array_flip (array trans)

将数组trans的key、value交换,就是key变value,而value变key了。
返回完成处理的数组。

例:
$a[0]="abc";
$a[1]="def";
After an array_flip() you get:
$a["abc"]=0; $a["def"]=1;

//***************************
array_count_values (PHP4 >= 4.0b4)

array array_count_values (array input)
统计input数组中各个值的个数。返回一个数组,以input的值做为key,以出现个数为value的新数组。

例:
$array = array (1, "hello", 1, "world", "hello");
array_count_values ($array);
// returns array (1=>2, "hello"=>2, "world"=>1)

//*****************************
array_merge (PHP4 )

array array_merge (array array1, array array2 [, array ...])
合并多个数组,把array2的内容加在array1的后面。返回结果数组。
假如是关联数组,以字串为key,出现同名的key,则后面的会覆盖前面的,而下标数组不会出现覆盖的现象,只是添加在后面。

例:
$array1 = array ("color" => "red", 2, 4);
$array2 = array ("a", "b", "color" => "green", "shape" => "trapezoid", 4);
array_merge ($array1, $array2);
//Resulting array will be array("color" => "green", 2, 4, "a", "b", "shape" => "trapezoid", 4).

See also array_merge_recursive().

//******************************
array_merge_recursive (PHP4 >= 4.0.1)

array array_merge_recursive (array array1, array array2 [, array ...])
递归合并数组,与上个函数基本类似。区别在于,在关联数组方面,它不是简单地把相同的key合并,还是生成一个二维数组来合并这相同key的value。(表达不清,不好意思,看例子吧)。

例:
$ar1 = array ("color" => array ("favorite" => "red"), 5);
$ar2 = array (10, "color" => array ("favorite" => "green", "blue"));
$result = array_merge_recursive ($ar1, $ar2);

//Resulting array will be array ("color" => array ("favorite" => array ("red", "green"), "blue"), 5, 10).


明白了吗?red,green被合并成一个新的数组了,放在favorite里。

See also array_merge().

//*******************************
array_intersect (PHP4 >= 4.0.1)

array array_intersect (array array1, array array2 [, array ...])
取多个数组的交集,返回包含交集元素的新数组。
以array1为基础的,所以了,假如是关联数组,那key值就是array1的了。见例子。


Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles