使用array_key_exist函数后未定义的键索引

时间:2017-07-19 11:38:34

标签: php arrays indexing

我有以下array

$instance_defaults = array(
    'title' => 'Popular Posts',
    'num_posts' => $instance['num_posts']
);

我注意到了 num_posts是未定义的索引。试图使用array_key_exist,但没有成功删除通知的任何想法?

public function form( $instance ) {
        $instance_defaults = array(
            'title' => 'Popular Posts',
            'num_posts' => $instance['num_posts']
        );

        $instance = wp_parse_args( $instance, $instance_defaults );
        $num_posts = esc_attr( $instance['num_posts'] );
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('num_posts'); ?>">
                <?php _e( "Number of posts to show: ", 'dx-posts-widgets'); ?>
            </label>
            <input class="widefat"
                   id="<?php echo $this->get_field_id('num_posts'); ?>"
                   name="<?php echo $this->get_field_name('num_posts'); ?>"
                   type="text" value="<?php echo $num_posts; ?>" />
        </p>
        <?php
    }

0 个答案:

没有答案