如何筛选数组并将字符串传递给数组值

时间:2016-10-25 11:29:07

标签: php arrays wordpress

我有一个我需要修改的Wordpress插件。

基本上,我有一个任意字符串,我想传递给一个特定的数组值,然后传递给过滤器('gmw_main_shortcode_form_args',$ form)。 代码如下,我需要过滤表单数组并将字符串传递给数组的“page_load_results”值:

$this->form     = apply_filters( 'gmw_main_shortcode_form_args', $form );
public function page_load_results() {`

    $page_load_options                           = $this->form['page_load_results'];
    $this->form['org_address']                   = '';
    $this->form['get_per_page']                  = ( !empty( $_GET[$this->form['url_px'].'per_page'] ) ) ? $_GET[$this->form['url_px'].'per_page'] :  current( explode( ",", $page_load_options['per_page'] ) );
    $this->form['radius']                        = ( !empty(  $page_load_options['radius'] ) ) ? $page_load_options['radius'] : 200;
    $this->form['search_results']['display_map'] = $page_load_options['display_map'];
    $this->form['units_array']                   = gmw_get_units_array(  $this->form['page_load_results']['units'] );

任何人都可以分享这样做的正确方法吗?

1 个答案:

答案 0 :(得分:0)

以下是使用array_filter

的示例
array_filter($form, function($k) {
    return $k == 'gmw_main_shortcode_form_args';
}, ARRAY_FILTER_USE_KEY);