search
HomeBackend DevelopmentPHP TutorialPHP操作数组的一些函数整理介绍_php技巧

在数组中搜索一个特定值,如果找到返回TRUE否则返回FALSE
boolean in_array(mixed needle,array haystack[,boolean strict])

在数组中找到一个指定的健,如果找到返回TRUE否则返回FALSE
boolean array_eky_exists(mixed key,array array)

在数组中搜索一个特定值,如果找到返回TRUE否则返回FALSE
boolean array_search(mixed needle,array haystack[,boolean strict])

获取数组所有键组成的新数组
array array_keys(array array[,mixed search_value])

获取数组所有值组成的新数组
array array_values(array array)

确定数组大小
integer count(array array[,int mode])

integer sizeof(array array[,int mode])

统计数组元素出现频率
array array_count_values(array array)

删除数组中重复的值,返回一个由唯一值组成的数组
array array_unique(array array)

逆置数组元素顺序,preserve_key如果为TRUE则数组键值顺序不变
array array_reverse(array array[,boolean preserve_key])

置换数组键和值
array array_flip(array array)

数组顺序排序,sort_flags参数可选,默认行为
SORT_NUMBERIC,按数值排序,对整数或浮点数排序很有用

SORT_REGULAR,按照ASCII值排序

SORT_STRING,按接近人所认识的正确顺序排序

asort函数键值顺序不变

void sort(array array[,int sort_flags])

void asort(array array[,int sort_flags])

数组逆序排序,sort_flags参数可选,默认行为
SORT_NUMBERIC,按数值排序,对整数或浮点数排序很有用

SORT_REGULAR,按照ASCII值排序

SORT_STRING,按接近人所认识的正确顺序排序

arsort函数键值顺序不变

void rsort(array array[,int sort_flags])

void arsort(array array[,int sort_flags])

数组自然排序
void natsort(array array)

不区分大小写的自然排序
void natcasesort(array array)

健键值对数组排序
boolean ksort(array array[,int sort_flags])

健键值对数组逆序排序
boolean krsort(array array[,int sort_flags])

根据用户自定义顺序排序
void usort(array array,callback function_name)

将数组合并到一起,返回一个联合的数组。array_merge后面覆盖前面,array_merge_recursive合并在一起
array array_merge(array array1[array array2……])//一个以上

array array_merge_recursive(array array1,array array2[,array ……])//两个以上

键和值组成新的数组
array array_combine(array key,array value)

返回数组一部分,从健offset开始,到offse+length位置结束
array array_slice(array array, int offset [,int length])

删除从offset开始到offset+length结束的所有元素,并以数组的形式返回删除的元素
array array_splice(array, int offset [,int length[,array peplacement]])

求数组的交集,键值为第一个数组中键值
array array_intersect(array array1,array array2[,arrayN……])

求数组的交集包含了键值相等,键值为第一个数组中键值
array array_intersect_assoc(array array1,array array2[,arrayN……])

求数组的差集,第一个数组在其他数组没有的值
array array_diff(array array1,array array2[,arrayN……])

求数组的差集,第一个数组在其他数组没有的值包含了键值相等
array array_diffassoc(array array1,array array2[,arrayN……])

返回数组中一个或多个键值
mixed array_rand(array array[,int num_entries])

随即洗牌函数
void shuffle(array input_array)

对数组中的值求和
mixed array_sum(array array);

将数组分解为一个多维数组,它包含了size个元素
array array_chunk(array array, int size [,boolean preserve_keys])

Statement
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
Optimize PHP Code: Reducing Memory Usage & Execution TimeOptimize PHP Code: Reducing Memory Usage & Execution TimeMay 10, 2025 am 12:04 AM

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

See all articles

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 Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software