标签:aop 数列 unset each turn class for content []
$options = array( ‘config‘ => array( ‘aaa‘ => 111, ‘bbb‘ => 222, ), ‘headers‘ => array( ‘Content-Type‘ => ‘application/json;charset=utf-8‘ ), ‘params‘ => array( ‘p1‘ => ‘hello‘, ‘p2‘ => ‘world‘, ), ‘signOptions‘ => array( ‘ccc‘ => ‘333‘, ), ); list($config,$headers,$params,$signOptions) = parseOptions($options,‘config‘,‘headers‘,‘params‘,‘signOptions‘); echo ‘<pre>‘; print_r($config); echo ‘<br>‘; print_r($headers); echo ‘<br>‘; print_r($params); echo ‘<br>‘; print_r($signOptions); echo ‘<br>‘; function parseOptions(array $options) { return doParseOptions($options,array_slice(func_get_args(), 1),false); } function doParseOptions(array $options,array $args,$allowExtraOptions) { $result = array(); foreach ($args as $arg) { if (isset($options[$arg])) { $result[] = $options[$arg]; unset($options[$arg]); } else { $result[] = null; } } if (!$allowExtraOptions && count($options) > 0) { throw new \InvalidArgumentException( ‘Unexpected options:‘ . implode(‘,‘, array_keys($options)) . ‘ Acceptable options are:‘ . implode(‘,‘, $args) ); } return $result; }
输出结果:
Array ( [aaa] => 111 [bbb] => 222 ) Array ( [Content-Type] => application/json;charset=utf-8 ) Array ( [p1] => hello [p2] => world ) Array ( [ccc] => 333 )
关注点:
php中的元组,获取参数列表函数
标签:aop 数列 unset each turn class for content []
原文地址:https://www.cnblogs.com/jun1019/p/10303287.html