0%
一想到时光匆匆,竟经不起半点挥霍,我就会对时间吝啬起来,因为此刻已过,便永不复还。
实例一
使用foreach修改数组
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| protected static function packedData($data, $key, $type = 'delete') { if ($type == 'update') { foreach ($data as &$order) { unset($order['useragent']); unset($order['ad_id']); unset($order['ad_channel']); unset($order['ad_url']); unset($order['ad_referer']); unset($order['ad_referer_host']); unset($order['ad_url_param']); unset($order['utm_source']); unset($order['utm_medium']); unset($order['utm_term']); unset($order['utm_content']); unset($order['utm_campaign']); } } return [ 'key' => $key, 'data' => $data ]; }
|
实例二
在没有返回值的情况下修改数组中的值
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| Route::get('hehe', function () { $datas = [1,2,3,4]; haha($datas); dump($datas); });
function haha(&$datas) { foreach ($datas as $data) { $data = $data * 2; } return $datas; }
|