each
这个函数在php7.2以后就弃用了
替代方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | function func_new_each(& $array ){ $res = array (); $key = key( $array ); if ( $key !== null){ next( $array ); $res [1] = $res [ 'value' ] = $array [ $key ]; $res [0] = $res [ 'key' ] = $key ; } else { $res = false; } return $res ; } 实例: while (list ( $key , $val ) = $this ->func_new_each( $para )) { if ( $key == "sign" || $key == "sign_type" || $val == "" ) continue ; else $para_filter [ $key ] = $para [ $key ]; } |
2. count
这个函数没有弃用,但是在7.2+上传递一个字符串参数的时候会报错:Warning: count(): Parameter must be an array or an object that implements Countable
替代方法:
1 2 3 4 5 6 7 | function func_new_count( $array_or_countable , $mode = COUNT_NORMAL){ if ( is_array ( $array_or_countable ) || is_object ( $array_or_countable )){ return count ( $array_or_countable , $mode ); } else { return 0; } } |
本文为Adamin90原创文章,转载无需和我联系,但请注明来自http://www.lixiaopeng.top