search
HomeBackend DevelopmentPHP TutorialPHP filters two-dimensional and three-dimensional arrays

<span> 1</span> <span>php
</span><span> 2</span><span> 3</span><span>$arr</span> =<span> [
</span><span> 4</span>         [1,3,5,7,9],
<span> 5</span>         [2,4,6,8,0<span>]
</span><span> 6</span><span>    ];
</span><span> 7</span><span>$arr2</span> =<span> [
</span><span> 8</span>         'list' =><span> [
</span><span> 9</span>             [1,3,5,7],
<span>10</span>             [2,4,6,8],
<span>11</span>             [3,2,9,0],
<span>12</span><span>        ]
</span><span>13</span><span>    ];
</span><span>14</span><span>$arr3</span> =<span> [
</span><span>15</span>         'list' =><span> [
</span><span>16</span>             [1,3,5,7],
<span>17</span>             [2,4,6,8],
<span>18</span>             [3,2,9,0<span>]
</span><span>19</span><span>        ]
</span><span>20</span><span>    ];
</span><span>21</span><span>22</span><span>$res</span> = <span>array_map</span>(<span>function</span>(<span>$arr</span><span>){
</span><span>23</span><span>return</span><span>array_filter</span>(<span>$arr</span>, <span>function</span>(<span>$v</span><span>) {
</span><span>24</span><span>return</span><span>$v</span> !== 5<span>;
</span><span>25</span><span>        });
</span><span>26</span>     }, <span>$arr</span><span>);
</span><span>27</span><span>28</span><span>$res2</span> = <span>array_map</span>(<span>function</span>(<span>$val</span><span>) {
</span><span>29</span><span>return</span><span>array_filter</span>(<span>$val</span>, <span>function</span>(<span>$v</span><span>) {
</span><span>30</span><span>return</span> !<span>in_array</span>(6, <span>$v</span><span>);
</span><span>31</span><span>        });
</span><span>32</span>     }, <span>$arr2</span><span>);
</span><span>33</span><span>34</span><span>$res3</span> =<span> [];
</span><span>35</span><span>array_walk</span>(<span>$arr3</span>, <span>function</span>(<span>$val</span>, <span>$key</span>) <span>use</span>(&<span>$res3</span><span>) {
</span><span>36</span><span>$res3</span>[<span>$key</span>] = <span>array_filter</span>(<span>$val</span>, <span>function</span>(<span>$v</span><span>) {
</span><span>37</span><span>return</span> !<span>in_array</span>(6, <span>$v</span><span>);
</span><span>38</span><span>        });
</span><span>39</span><span>    });
</span><span>40</span><span>41</span><span>var_dump</span>(<span>$res2</span><span>);
</span><span>42</span><span>var_dump</span>(<span>$res3</span>);

The above introduces PHP filtering two-dimensional arrays and three-dimensional arrays, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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
function是什么意思function是什么意思Aug 04, 2023 am 10:33 AM

function是函数的意思,是一段具有特定功能的可重复使用的代码块,是程序的基本组成单元之一,可以接受输入参数,执行特定的操作,并返回结果,其目的是封装一段可重复使用的代码,提高代码的可重用性和可维护性。

使用C#中的Array.Sort函数对数组进行排序使用C#中的Array.Sort函数对数组进行排序Nov 18, 2023 am 10:37 AM

标题:C#中使用Array.Sort函数对数组进行排序的示例正文:在C#中,数组是一种常用的数据结构,经常需要对数组进行排序操作。C#提供了Array类,其中有Sort方法可以方便地对数组进行排序。本文将演示如何使用C#中的Array.Sort函数对数组进行排序,并提供具体的代码示例。首先,我们需要了解一下Array.Sort函数的基本用法。Array.So

解决“[Vue warn]: Failed to resolve filter”错误的方法解决“[Vue warn]: Failed to resolve filter”错误的方法Aug 19, 2023 pm 03:33 PM

解决“[Vuewarn]:Failedtoresolvefilter”错误的方法在使用Vue进行开发的过程中,我们有时候会遇到一个错误提示:“[Vuewarn]:Failedtoresolvefilter”。这个错误提示通常出现在我们在模板中使用了一个未定义的过滤器的情况下。本文将介绍如何解决这个错误并给出相应的代码示例。当我们在Vue的

"enumerate()"函数在Python中的用途是什么?"enumerate()"函数在Python中的用途是什么?Sep 01, 2023 am 11:29 AM

在本文中,我们将了解enumerate()函数以及Python中“enumerate()”函数的用途。什么是enumerate()函数?Python的enumerate()函数接受数据集合作为参数并返回一个枚举对象。枚举对象以键值对的形式返回。key是每个item对应的索引,value是items。语法enumerate(iterable,start)参数iterable-传入的数据集合可以作为枚举对象返回,称为iterablestart-顾名思义,枚举对象的起始索引由start定义。如果我们忽

MySQL.proc表的作用和功能详解MySQL.proc表的作用和功能详解Mar 16, 2024 am 09:03 AM

MySQL.proc表的作用和功能详解MySQL是一种流行的关系型数据库管理系统,开发者在使用MySQL时常常会涉及到存储过程(StoredProcedure)的创建和管理。而MySQL.proc表则是一个非常重要的系统表,它存储了数据库中所有的存储过程的相关信息,包括存储过程的名称、定义、参数等。在本文中,我们将详细解释MySQL.proc表的作用和功能

简单明了的PHP array_merge_recursive()函数使用方法简单明了的PHP array_merge_recursive()函数使用方法Jun 27, 2023 pm 01:48 PM

在进行PHP编程时,我们常常需要对数组进行合并。PHP提供了array_merge()函数来完成数组合并的工作,不过当数组中存在相同的键时,该函数会覆盖原有的值。为了解决这个问题,PHP在语言中还提供了一个array_merge_recursive()函数,该函数可以合并数组并保留相同键的值,使得程序的设计变得更加灵活。array_merge

如何使用PHP中的array_combine函数将两个数组拼成关联数组如何使用PHP中的array_combine函数将两个数组拼成关联数组Jun 26, 2023 pm 01:41 PM

在PHP中,有许多强大的数组函数可以使数组的操作更加方便和快捷。当我们需要将两个数组拼成一个关联数组时,可以使用PHP的array_combine函数来实现这一操作。这个函数实际上是用来将一个数组的键作为另一个数组的值,合并成一个新的关联数组。接下来,我们将会讲解如何使用PHP中的array_combine函数将两个数组拼成关联数组。了解array_comb

Springboot中filter的原理与注册方法是什么Springboot中filter的原理与注册方法是什么May 11, 2023 pm 08:28 PM

1、filter先看下web服务器的filter所处的位置。filter是一个前后连接的链,前面处理完成之后传递给下一个filter处理。1.1filter的接口定义publicinterfaceFilter{//初始化方法,整个生命周期中只执行一次。//在init方法成功(失败如抛异常等)执行完前,不能提供过滤服务。//参数FilterConfig用于获取初始化参数publicvoidinit(FilterConfigfilterConfig)throwsServletException;//

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

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 agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version