Heim > Backend-Entwicklung > PHP-Tutorial > PHP 过滤二维数组跟三维数组

PHP 过滤二维数组跟三维数组

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-13 12:28:56
Original
1026 Leute haben es durchsucht

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>);
Nach dem Login kopieren

 

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
Array zu Array
Aus 1970-01-01 08:00:00
0
0
0
PHP-Array
Aus 1970-01-01 08:00:00
0
0
0
Array
Aus 1970-01-01 08:00:00
0
0
0
PHP-Array-Transformation
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage