Rumah > pembangunan bahagian belakang > tutorial php > PHP 过滤二维数组和三维数组,php二维数组数组_PHP教程

PHP 过滤二维数组和三维数组,php二维数组数组_PHP教程

WBOY
Lepaskan: 2016-07-12 08:57:16
asal
1217 orang telah melayarinya

PHP 过滤二维数组和三维数组,php二维数组数组

<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>);
Salin selepas log masuk

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1109848.htmlTechArticlePHP 过滤二维数组和三维数组,php二维数组数组 1 ? php 2 3 $arr = [ 4 [1,3,5,7,9], 5 [2,4,6,8,0 ] 6 ]; 7 $arr2 = [ 8 'list' = [ 9 [1,3,5,7], 10 [2,4,6,8], 11 [3,2,9,...
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan