我在一个函数中有3个数组,我想返回它,因为它是用逗号分隔的。尝试了array_merge
,array_combine
,array_merge_recursive
以及+
运算符,但没有任何效果。
这是我的功能:
function svca_icon_fields() {
$icon = array (
'type' => 'dropdown',
'heading' => __( 'Select Icon Type', 'svca-addon' ),
'param_name' => 'icon_type',
'description' => __( 'Select Icon Type', 'svca-addon' ),
'value' => array(
__( 'No Icon', 'svca-addon' ) => 'noicon',
__( 'Font Awesome', 'svca-addon' ) => 'fontawesome',
__( 'Open Iconic', 'svca-addon' ) => 'openiconic',
__( 'Typicons', 'svca-addon' ) => 'typicons',
__( 'Entypo', 'svca-addon' ) => 'entypo',
__( 'Linecons', 'svca-addon' ) => 'linecons',
),
);
$fa = array(
'type' => 'iconpicker',
'value' => 'fa fa-star',
'heading' => __( 'Icon', 'svca-addon' ),
'param_name' => 'fa_icon',
'description' => __( 'Pick an Icon to represent your package.', 'svca-addon' ),
'settings' => array(
'emptyIcon' => false,
'type' => 'fontawesome',
'iconsPerPage' => 200,
),
'dependency' => array( 'element' => 'icon_type', 'value' => 'fontawesome' ),
);
$oi = array(
'type' => 'iconpicker',
'value' => 'vc-oi vc-oi-eye',
'heading' => __( 'Icon', 'svca-addon' ),
'param_name' => 'oi_icon',
'description' => __( 'Pick an Icon to represent your package.', 'svca-addon' ),
'settings' => array(
'emptyIcon' => false,
'type' => 'openiconic',
'iconsPerPage' => 200,
),
'dependency' => array( 'element' => 'icon_type', 'value' => 'openiconic' ),
);
$data = array_merge_recursive( $icon, $fa, $oi );
//$data = array_merge( $icon, $fa, $oi );
//$data = array_combine( $icon, $fa, $oi );
//$data = $icon + $fa + $oi + $ti + $et + $li;
//$data = $icon . $fa . $oi . $ti . $et . $li;
//return $data;
echo '<pre>';
print_r( $data );
echo '</pre>';
}
而且,这就是我想要回归的内容:
array (
'type' => 'dropdown',
'heading' => __( 'Select Icon Type', 'svca-addon' ),
'param_name' => 'icon_type',
'description' => __( 'Select Icon Type', 'svca-addon' ),
'value' => array(
__( 'No Icon', 'svca-addon' ) => 'noicon',
__( 'Font Awesome', 'svca-addon' ) => 'fontawesome',
__( 'Open Iconic', 'svca-addon' ) => 'openiconic',
__( 'Typicons', 'svca-addon' ) => 'typicons',
__( 'Entypo', 'svca-addon' ) => 'entypo',
__( 'Linecons', 'svca-addon' ) => 'linecons',
),
), //Seperated By Comma
array(
'type' => 'iconpicker',
'value' => 'fa fa-star',
'heading' => __( 'Icon', 'svca-addon' ),
'param_name' => 'fa_icon',
'description' => __( 'Pick an Icon to represent your package.', 'svca-addon' ),
'settings' => array(
'emptyIcon' => false,
'type' => 'fontawesome',
'iconsPerPage' => 200,
),
'dependency' => array( 'element' => 'icon_type', 'value' => 'fontawesome' ),
), //Seperated By Comma
array(
'type' => 'iconpicker',
'value' => 'vc-oi vc-oi-eye',
'heading' => __( 'Icon', 'svca-addon' ),
'param_name' => 'oi_icon',
'description' => __( 'Pick an Icon to represent your package.', 'svca-addon' ),
'settings' => array(
'emptyIcon' => false,
'type' => 'openiconic',
'iconsPerPage' => 200,
),
'dependency' => array( 'element' => 'icon_type', 'value' => 'openiconic' ),
), //Seperated By Comma
花了最近2个小时才弄清楚这一点没有成功 感谢
答案 0 :(得分:0)
这应该可以随心所欲地使用
return array($icon,$fa,$oi);
答案 1 :(得分:0)
无法返回三个阵列。 尝试返回包含三个数组内容的多维数组。
return array(your,arrays,here);
答案 2 :(得分:0)
将其归还:
//your code above;
return array(
'fa' => $fa,
'oi' => $oi,
'icon' => $icon
);
使用索引要容易一些,因此您无需记住订单。 所以,如果
$a = svca_icon_fields();
$icon = $a['icon'];// instead of $a[2];
答案 3 :(得分:0)
函数和方法只能返回一个值,因此必须返回:
$data = array( $icon, $fa, $oi );
$return $data;
但是,如果要将返回值分配给三个数组,可以这样做:
list( $icon, $fa, $oi ) = svca_icon_fields();
然后您将拥有三个不同的数组(您可以使用首选的数组名称更改$icon
等)。
list()
是一个php语言构造函数,它在一个操作中分配变量列表。请注意list()
只能 与非关联数组一起使用。