我创建的函数返回正常数组:
sh.Range("B2").FormulaR1C1 = "=SUM(VolumeDat!R[3]C[1]:R[23]C[0])"
我希望像这样的关联数组就位:
function get_list_array () {
$list_object = get_list_objects();
foreach ( $list_object as $every_object) {
$list_array[] = array (
"wprm_$every_object->name" => array (
'name' => _x("$every_object->label", , 'test'),
'singular_name' => _x("$every_object->name", , 'test'),));
}
return $list_array ;
}
var_dump ($list_array);
array(2) {
[0]=> array(1) { ["object_1"]=> array(2) {
["name"]=> string(10)
"name_object1" ["singular_name"]=> string(15) "singular_name_object1" } }
[1]=> array(1) { ["object_2"]=> array(2) {
["name"]=> string(4)
"name_object2" ["singular_name"]=> string(10) "singular_name2" } } }
我知道如何修改我的函数以获取第二个输出。
答案 0 :(得分:0)
您可以通过以下操作将实际需要的数组包装到另一个数组中:
$list_array[] = array(
"wprm_$every_object->name" => array(
相反,您应该直接将新数组直接分配给$list_array
:
$list_array["wprm_$every_object->name"] = array(
另外,请考虑如何缩进代码,因为哇。您的函数可以如下所示:
function get_list_array () {
$list_object = get_list_objects();
foreach ($list_object as $every_object) {
$list_array["wprm_$every_object->name"] = array(
'name' => _x("$every_object->label", , 'test'),
'singular_name' => _x("$every_object->name", , 'test'),
);
}
return $list_array;
}