这是我的递归函数,默认发送参数,这可以正常工作。
<?php
function tf_wp_parse_args( &$a, $b ) {
$a = (array) $a;
$b = (array) $b;
$result = $b;
foreach ( $a as $k => &$v ) {
if ( is_array( $v ) && isset( $result[ $k ] ) ) {
$result[ $k ] = tf_wp_parse_args( $v, $result[ $k ] );
} else {
$result[ $k ] = $v;
}
}
return $result;
}
// example
$args = array(
'name' => 'name_01_field',
'params' => array('id'=> 'field_id_01'),
);
$defaults = array(
'name' => '',
'title' => '',
'description' => '',
'params' => array('labels'=>array(),'id' => ''),
);
$args = tf_wp_parse_args( isset($args) ? $args : array() , $defaults );
var_dump( $args );
/*
array (size=4)
'name' => string 'name_01_field' (length=13)
'title' => string '' (length=0)
'description' => string '' (length=0)
'params' =>
array (size=2)
'labels' =>
array (size=0)
empty
'id' => string 'field_id_01' (length=11)
*/
?>
但是如果我激活调试,我会收到以下错误:Strict standards: Only variables should be passed by reference in
https://gyazo.com/05198e763afd4b6859fb1f50bb4935fd
可能会发生什么?