PHP器皿

Jun 13, 2016 pm 01:19 PM
array boolean key state

PHP容器
每种语言的容器都不太一样,最起码名字不一样,不过有一个是一样的,就是Array~
Java是我目前见过最多容器类型的语言了~
PHP的弱类型特征,使得容器看起来很OO。


Array

boolean print_r($array); //用来输出数组,还有用while遍历打印
is_array()
Copy after login




create:array、range、list
$state[0] = "0";
$state[1] = "1";
$state[]  = "2";  //数字索引才能这么玩的
echo $state[0].$state[2];
//	长度无需提前定义,动态

$state["key"] = "value";
//	还可以使用字符串做下标,全对象的吗?


$array1 = array("OH" => "Ohio", "CA" => "California", "HI" => "Hawaii");
//	这不就是OC的Dictionary的创建方式么~




//  便利地创建有序数组
//  操作数据库时,听说就是用list来玩,可以一次读取多个对象
Copy after login



常用array函数
boolean in_array($tag, $array    [boolean]);//最后是否匹配类型
boolean array_key_exists(key, $array);


array array_keys($array, [$key]);  //可选参数的意思是?
array array_values($array);
key   array_search($value, $array, [boolean]); //可选,类型匹配?
array echo($array) =>返回当前的key-value

key key($array)   => 类似jdbc读取ResultSet
key next($array)  => 下一个
key prev($array)  => 上一个
key reset($array) => 指针回到开头
key end($array)   => 最后一个
key current($array) => 当前,但不移动指针,简直就和文件操作一个样子~
Copy after login


//  书上说很有用的一个函数,将数据传给函数,特附上例子
boolean array_walk($array, callback function,  [可选传入函数的第三个参数C]);

    //  fuck,函数接口是两个参数,也可以有第三个参数,对应C
    //  想改值就传指针~,PHP也有指针玩耶
    function sanitize_data(&$value, $key) {
        $value = strip_tags($value);
    }

    $ay['keyword'] = "yes";
    array_walk($ay['keyword'],"sanitize_data");

$array1 = array("OH","CA","NY","HI","CT");
$array3 = array("TX","MD","NE","OH","HI");
$intersection = array_intersect($array1, $array3);
print_r($intersection);
Copy after login


//P85,抄个名字~
array_reverse()逆置
array_flip()键值交换
count()
array_count_values()
array_unique()去除重复的值
Copy after login


排序竟然有那么多函数>
sort()
natsort()
natcasesort()
rsort()
asort()
array_multisort()
arsort()
ksort()
krsort()
usort()
Copy after login



//  合并、拆分、接合、分解
array_combine()
array_merge()
array_merge_recursive()
array_slice()
array_splice()
array_intersect()
array_intersect_assoc()
array_diff()
array_diff_assoc



array_rand()
shuffle()
array_sum()array_chunk()
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 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)

Hot Topics

Java Tutorial
1673
14
PHP Tutorial
1278
29
C# Tutorial
1257
24
What is the difference between Boolean and boolean in Java What is the difference between Boolean and boolean in Java May 05, 2023 pm 07:40 PM

Preface Someone asked, aren’t there only two types of Boolean values: true and false? Why does the attribute he defined have a null value? We should first make it clear that boolean is the basic data type of Java, and Boolean is a class of Java. The boolean type will assign false to the attribute during the "assign zero value" phase. Boolean is a class that will assign null to the object in the "assign zero value" phase. If it is a static property, it will be assigned when the class is loaded. If it is a normal class attribute, the value will be assigned when the object is instantiated. These two points can help you understand the "class loading mechanism" and "object creation process". Class loading mechanism: Loading: Get the binary byte stream of the class based on the full name of the class, and

What does the identity attribute in SQL mean? What does the identity attribute in SQL mean? Feb 19, 2024 am 11:24 AM

What is Identity in SQL? Specific code examples are needed. In SQL, Identity is a special data type used to generate auto-incrementing numbers. It is often used to uniquely identify each row of data in a table. The Identity column is often used in conjunction with the primary key column to ensure that each record has a unique identifier. This article will detail how to use Identity and some practical code examples. The basic way to use Identity is to use Identit when creating a table.

How SpringBoot monitors redis Key change events How SpringBoot monitors redis Key change events May 26, 2023 pm 01:55 PM

1. Function Overview Keyspace notification allows clients to receive events that modify Rediskey changes in some way by subscribing to channels or patterns. All commands that modify key keys. All keys that received the LPUSHkeyvalue[value…] command. All expired keys in the db database. Events are distributed through Redis's subscription and publishing functions (pub/sub), so all clients that support subscription and publishing functions can directly use the keyspace notification function without any modifications. Because the current subscription and publishing functions of Redis adopt a fireandforget strategy, if your program

How to solve the problem of batch deletion of key values ​​in redis How to solve the problem of batch deletion of key values ​​in redis May 31, 2023 am 08:59 AM

Problems encountered: During the development process, you will encounter keys that need to be deleted in batches according to certain rules, such as login_logID (ID is a variable). Now you need to delete data such as "login_log*", but redis itself only has batch query. Command keys for class key values, but there is no command for batch deletion of a certain class. Solution: Query first, then delete, use xargs to pass parameters (xargs can convert pipe or standard input (stdin) data into command line parameters), execute the query statement first, and then remove the queried key value and the original del parameters. delete. redis-cliKEYSkey* (search condition)|xargsr

Unpatchable Yubico two-factor authentication key vulnerability breaks the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices Unpatchable Yubico two-factor authentication key vulnerability breaks the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices Sep 04, 2024 pm 06:32 PM

An unpatchable Yubico two-factor authentication key vulnerability has broken the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices. The Feitian A22 JavaCard and other devices using Infineon SLB96xx series TPMs are also vulnerable.All

Convert string to boolean using java's Boolean.valueOf() function Convert string to boolean using java's Boolean.valueOf() function Jul 24, 2023 pm 05:15 PM

Use Java's Boolean.valueOf() function to convert a string to a Boolean value. In Java programming, you often encounter situations where you need to convert a string to a Boolean value. Java provides a convenient way to achieve this requirement, using the Boolean.valueOf() function. This function can convert a Boolean value represented by a string into the corresponding Boolean type. Let's take a closer look at the usage of Boolean.valueOf(). Given a string, we

Sort array using Array.Sort function in C# Sort array using Array.Sort function in C# Nov 18, 2023 am 10:37 AM

Title: Example of using the Array.Sort function to sort an array in C# Text: In C#, array is a commonly used data structure, and it is often necessary to sort the array. C# provides the Array class, which has the Sort method to conveniently sort arrays. This article will demonstrate how to use the Array.Sort function in C# to sort an array and provide specific code examples. First, we need to understand the basic usage of the Array.Sort function. Array.So

Simple and clear method to use PHP array_merge_recursive() function Simple and clear method to use PHP array_merge_recursive() function Jun 27, 2023 pm 01:48 PM

When programming in PHP, we often need to merge arrays. PHP provides the array_merge() function to complete array merging, but when the same key exists in the array, this function will overwrite the original value. In order to solve this problem, PHP also provides an array_merge_recursive() function in the language, which can merge arrays and retain the values ​​of the same keys, making the program design more flexible. array_merge

See all articles