批改状态:合格
老师批语:
//创建一个区间里的数组$num = range(1,100);$a = array_map(function($item){return $item%2 ==0 ? ($item . '<br>'):null;},$num);print_r($a);```AC- array_filter 的使用,返回通过回调函数过滤数组,过滤后的数组键值对不变```php// Filters elements of an array using a callback function$res = array_filter($a,function($item){return $item;});print_r($res);
// Return all the values of an arrayarray_values($res);
// Return all the keys or a subset of the keys of an arrayprint_r( array_keys(array('name'=>'zhangsna')));
2.分别举例说明函数的剩余参数与参数引用~
剩余参数可以有两种表现形式,结果一样
function num(...$arg){print_r($arg);}num(1,2,3);
function num(...$arg){print_r($arg);}$arr = [1,2,3];num(...$arr);
// 引用参数$a = 123;function test(&$a){return ++$a;}echo test($a) . '===' . $a;
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号