PHP 过滤二维数组跟三维数组
PHP 过滤二维数组和三维数组
<span style="color: #008080;"> 1</span> <span style="color: #000000;">php</span><span style="color: #008080;"> 2</span> <span style="color: #008080;"> 3</span> <span style="color: #800080;">$arr</span> =<span style="color: #000000;"> [</span><span style="color: #008080;"> 4</span> [1,3,5,7,9],<span style="color: #008080;"> 5</span> [2,4,6,8,0<span style="color: #000000;">]</span><span style="color: #008080;"> 6</span> <span style="color: #000000;"> ];</span><span style="color: #008080;"> 7</span> <span style="color: #800080;">$arr2</span> =<span style="color: #000000;"> [</span><span style="color: #008080;"> 8</span> 'list' =><span style="color: #000000;"> [</span><span style="color: #008080;"> 9</span> [1,3,5,7],<span style="color: #008080;">10</span> [2,4,6,8],<span style="color: #008080;">11</span> [3,2,9,0],<span style="color: #008080;">12</span> <span style="color: #000000;"> ]</span><span style="color: #008080;">13</span> <span style="color: #000000;"> ];</span><span style="color: #008080;">14</span> <span style="color: #800080;">$arr3</span> =<span style="color: #000000;"> [</span><span style="color: #008080;">15</span> 'list' =><span style="color: #000000;"> [</span><span style="color: #008080;">16</span> [1,3,5,7],<span style="color: #008080;">17</span> [2,4,6,8],<span style="color: #008080;">18</span> [3,2,9,0<span style="color: #000000;">]</span><span style="color: #008080;">19</span> <span style="color: #000000;"> ]</span><span style="color: #008080;">20</span> <span style="color: #000000;"> ];</span><span style="color: #008080;">21</span> <span style="color: #008080;">22</span> <span style="color: #800080;">$res</span> = <span style="color: #008080;">array_map</span>(<span style="color: #0000ff;">function</span>(<span style="color: #800080;">$arr</span><span style="color: #000000;">){</span><span style="color: #008080;">23</span> <span style="color: #0000ff;">return</span> <span style="color: #008080;">array_filter</span>(<span style="color: #800080;">$arr</span>, <span style="color: #0000ff;">function</span>(<span style="color: #800080;">$v</span><span style="color: #000000;">) {</span><span style="color: #008080;">24</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$v</span> !== 5<span style="color: #000000;">;</span><span style="color: #008080;">25</span> <span style="color: #000000;"> });</span><span style="color: #008080;">26</span> }, <span style="color: #800080;">$arr</span><span style="color: #000000;">);</span><span style="color: #008080;">27</span> <span style="color: #008080;">28</span> <span style="color: #800080;">$res2</span> = <span style="color: #008080;">array_map</span>(<span style="color: #0000ff;">function</span>(<span style="color: #800080;">$val</span><span style="color: #000000;">) {</span><span style="color: #008080;">29</span> <span style="color: #0000ff;">return</span> <span style="color: #008080;">array_filter</span>(<span style="color: #800080;">$val</span>, <span style="color: #0000ff;">function</span>(<span style="color: #800080;">$v</span><span style="color: #000000;">) {</span><span style="color: #008080;">30</span> <span style="color: #0000ff;">return</span> !<span style="color: #008080;">in_array</span>(6, <span style="color: #800080;">$v</span><span style="color: #000000;">);</span><span style="color: #008080;">31</span> <span style="color: #000000;"> });</span><span style="color: #008080;">32</span> }, <span style="color: #800080;">$arr2</span><span style="color: #000000;">);</span><span style="color: #008080;">33</span> <span style="color: #008080;">34</span> <span style="color: #800080;">$res3</span> =<span style="color: #000000;"> [];</span><span style="color: #008080;">35</span> <span style="color: #008080;">array_walk</span>(<span style="color: #800080;">$arr3</span>, <span style="color: #0000ff;">function</span>(<span style="color: #800080;">$val</span>, <span style="color: #800080;">$key</span>) <span style="color: #0000ff;">use</span>(&<span style="color: #800080;">$res3</span><span style="color: #000000;">) {</span><span style="color: #008080;">36</span> <span style="color: #800080;">$res3</span>[<span style="color: #800080;">$key</span>] = <span style="color: #008080;">array_filter</span>(<span style="color: #800080;">$val</span>, <span style="color: #0000ff;">function</span>(<span style="color: #800080;">$v</span><span style="color: #000000;">) {</span><span style="color: #008080;">37</span> <span style="color: #0000ff;">return</span> !<span style="color: #008080;">in_array</span>(6, <span style="color: #800080;">$v</span><span style="color: #000000;">);</span><span style="color: #008080;">38</span> <span style="color: #000000;"> });</span><span style="color: #008080;">39</span> <span style="color: #000000;"> });</span><span style="color: #008080;">40</span> <span style="color: #008080;">41</span> <span style="color: #008080;">var_dump</span>(<span style="color: #800080;">$res2</span><span style="color: #000000;">);</span><span style="color: #008080;">42</span> <span style="color: #008080;">var_dump</span>(<span style="color: #800080;">$res3</span>);

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

C语言return的用法有:1、对于返回值类型为void的函数,可以使用return语句来提前结束函数的执行;2、对于返回值类型不为void的函数,return语句的作用是将函数的执行结果返回给调用者;3、提前结束函数的执行,在函数内部,我们可以使用return语句来提前结束函数的执行,即使函数并没有返回值。

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

源码:publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#输出上述代码的输出可以简单地得出结论:return在finally之前执行,我们来看下字节码层面上发生了什么事情。下面截取case1方法的部分字节码,并且对照源码,将每个指令的含义注释在

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

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

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

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

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