欢迎各位兄弟 发布技术文章
这里的技术是共享的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | header( "Content-Type:text/html;charset=utf-8" ); $a = array ( array ( 'name' => 'hah' , 'sex' => '女' , 'age' =>19), array ( 'name' => '嘎嘎' , 'sex' => '男' , 'age' =>20), array ( 'name' => '嘿嘿' , 'sex' => '女' , 'age' =>19), array ( 'name' => '呵呵' , 'sex' => '女' , 'age' =>19), array ( 'name' => 'keke' , 'sex' => '男' , 'age' =>19) ); function filter( $arr ){ return $arr [ 'sex' ]; } print_r( array_map ( 'filter' , $a )); //这里你将会返回全部都是性别的信息 Array ( [0] => 女 [1] => 男 [2] => 女 [3] => 女 [4] => 男 ) /*--------------------------------------------------------------*/ print_r( array_filter ( $a , 'filter' )); //这里会输出原来的数组 array ( array ( 'name' => 'hah' , 'sex' => '女' , 'age' =>19), array ( 'name' => '嘎嘎' , 'sex' => '男' , 'age' =>20), array ( 'name' => '嘿嘿' , 'sex' => '女' , 'age' =>19), array ( 'name' => '呵呵' , 'sex' => '女' , 'age' =>19), array ( 'name' => 'keke' , 'sex' => '男' , 'age' =>19) ); /*--------------------------------------------------------------*/ function filter( $arr ){ return $arr [ 'sex' ]== '男' ; } print_r( array_map ( 'filter' , $a )); //这里将会输出的性别与上面条件比较的布尔值 Array ( [0] => 1 [1] => [2] => 1 [3] => 1 [4] => ) /*--------------------------------------------------------------*/ print_r( array_filter ( $a , 'filter' )); //这里输出如下 Array ( [1] => Array ( [name] => 嘎嘎 [sex] => 男 [age] => 20 ) [4] => Array ( [name] => keke [sex] => 男 [age] => 19 ) ) |