【问题标题】:How to pass values inside array?如何在数组中传递值?
【发布时间】:2018-04-07 22:02:45
【问题描述】:

我有一个包含这个选项的数组

    $choices = array(
        '-- Make a Selection --' => '',
        'Choice 1' => 'Choice 1',
        'Choice 2' => 'Choice 2',
        'Choice 3' => 'Choice 3',
        'Choice 4' => 'Choice 4',
        'Choice 5' => 'Choice 5'
    );
    return $choices;

我需要使用自定义字段重复器(高级自定义字段)填充的选项

if(have_rows('lista_de_variables')) : while(have_rows('lista_de_variables')) : the_row(); 

    $choice = get_sub_field('dimension');

endwhile; endif;

// this function returns an array of 
// label => value pairs to be used in
// a the select field
$choices = array(
    '-- Make a Selection --' => '',
    $choice => $choice,
);
return $choices;

【问题讨论】:

  • 尝试使用array_merge

标签: php arrays wordpress


【解决方案1】:

而不是使用

$choices = array(
    '-- Make a Selection --' => '',
    $choice => $choice,
);

你可以简单地使用

$choices[$choice] = $choice;

【讨论】:

    【解决方案2】:

    你应该直接使用数组的字段

    $choice = get_field('lista_de_variables');
    print_r($choice);
    

    有关 acf 的中继器字段的更多信息,您可以 访问https://support.advancedcustomfields.com/forums/topic/print-repeater-array-values/

    【讨论】:

      猜你喜欢
      • 2016-07-04
      • 2017-06-13
      • 2017-10-13
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-23
      • 1970-01-01
      相关资源
      最近更新 更多