Title: Warning: array_key_exists() expects parameter 2 to be array
Last modified: August 24, 2016

---

# Warning: array_key_exists() expects parameter 2 to be array

 *  Resolved [WilliamTai](https://wordpress.org/support/users/williamtai/)
 * (@williamtai)
 * [11 years ago](https://wordpress.org/support/topic/warning-array_key_exists-expects-parameter-2-to-be-array-2/)
 * Dear Sir,
    I have the same issue about PHP warning message in the topic: [https://wordpress.org/support/topic/warnings-at-top-of-pages-with-code-pointing-to-top-10](https://wordpress.org/support/topic/warnings-at-top-of-pages-with-code-pointing-to-top-10)
 * I modified some code in top-10.php and it’s not totally fixed, the error_log 
   as below:
 * PHP Warning: array_key_exists() expects parameter 2 to be array, null given in/
   wp-content/plugins/top-10/top-10.php on line 234
 * PHP Warning: array_key_exists() expects parameter 2 to be array, null given in/
   wp-content/plugins/top-10/top-10.php on line 264
 * [https://wordpress.org/plugins/top-10/](https://wordpress.org/plugins/top-10/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [11 years ago](https://wordpress.org/support/topic/warning-array_key_exists-expects-parameter-2-to-be-array-2/#post-6111060)
 * What happens when you add this code at line 225 of top-10.php
 *     ```
       global $wpdb, $tptn_settings;
       if ( empty( $wp ) ) {
       global $wp;
       }
       ```
   
 *  Thread Starter [WilliamTai](https://wordpress.org/support/users/williamtai/)
 * (@williamtai)
 * [11 years ago](https://wordpress.org/support/topic/warning-array_key_exists-expects-parameter-2-to-be-array-2/#post-6111064)
 * I’m not add the code, I just replaced it.
 *     ```
       function tptn_parse_request( $wp ) {
          	global $wpdb, $tptn_settings;
           if ( empty( $wp ) ) {
           global $wp;
           }
   
       	$table_name = $wpdb->base_prefix . "top_ten";
       	$top_ten_daily = $wpdb->base_prefix . "top_ten_daily";
       	$str = '';
   
       	if ( array_key_exists( 'top_ten_id', $wp->query_vars ) && array_key_exists( 'activate_counter', $wp->query_vars ) && $wp->query_vars['top_ten_id'] != '' ) {
   
       		$id = intval( $wp->query_vars['top_ten_id'] );
       		$blog_id = intval( $wp->query_vars['top_ten_blog_id'] );
       		$activate_counter = intval( $wp->query_vars['activate_counter'] );
   
       		if ( $id > 0 ) {
   
       			if ( ( 1 == $activate_counter ) || ( 11 == $activate_counter ) ) {
   
       				$tt = $wpdb->query( $wpdb->prepare( "INSERT INTO {$table_name} (postnumber, cntaccess, blog_id) VALUES('%d', '1', '%d') ON DUPLICATE KEY UPDATE cntaccess= cntaccess+1 ", $id, $blog_id ) );
   
       				$str .= ( FALSE === $tt ) ? 'tte' : 'tt' . $tt;
       			}
   
       			if ( ( 10 == $activate_counter ) || ( 11 == $activate_counter ) ) {
   
       				$current_date = gmdate( 'Y-m-d H', current_time( 'timestamp', 0 ) );
   
       				$ttd = $wpdb->query( $wpdb->prepare( "INSERT INTO {$top_ten_daily} (postnumber, cntaccess, dp_date, blog_id) VALUES('%d', '1', '%s', '%d' ) ON DUPLICATE KEY UPDATE cntaccess= cntaccess+1 ", $id, $current_date, $blog_id ) );
   
       				$str .= ( FALSE === $ttd ) ? ' ttde' : ' ttd' . $ttd;
       			}
       		}
       		Header( "content-type: application/x-javascript" );
       		echo '<!-- ' . $str . ' -->';
   
       		//stop anything else from loading as it is not needed.
       		exit;
   
       	} elseif ( array_key_exists( 'top_ten_id', $wp->query_vars ) && array_key_exists( 'view_counter', $wp->query_vars ) && $wp->query_vars['top_ten_id'] != '' ) {
   
       		$id = intval( $wp->query_vars['top_ten_id'] );
   
       		if ( $id > 0 ) {
   
       			$output = get_tptn_post_count( $id );
   
       			Header( "content-type: application/x-javascript" );
       			echo 'document.write("' . $output . '")';
   
       			//stop anything else from loading as it is not needed.
       			exit;
       		}
   
       	} else {
       		return;
       	}
       }
       add_action( 'wp', 'tptn_parse_request' );
       ```
   
 *     ```
       PHP Warning: array_key_exists() expects parameter 2 to be array, null given in /wp-content/plugins/top-10/top-10.php on line 234
   
       PHP Warning: array_key_exists() expects parameter 2 to be array, null given in /wp-content/plugins/top-10/top-10.php on line 264
       ```
   
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [11 years ago](https://wordpress.org/support/topic/warning-array_key_exists-expects-parameter-2-to-be-array-2/#post-6111080)
 * Hi,
 * Could you please try changing the last line of your code i.e. the add_action 
   to:
 *     ```
       add_action( 'parse_request', 'tptn_parse_request' );
       ```
   
 * Could you please let me know if this removes the warning and also tracks the 
   posts?
 *  Thread Starter [WilliamTai](https://wordpress.org/support/users/williamtai/)
 * (@williamtai)
 * [11 years ago](https://wordpress.org/support/topic/warning-array_key_exists-expects-parameter-2-to-be-array-2/#post-6111125)
 * Hi,
    It works for me, all the warning is gone and the plugin also tracks the 
   posts.
 * thanks for your help.
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [11 years ago](https://wordpress.org/support/topic/warning-array_key_exists-expects-parameter-2-to-be-array-2/#post-6111131)
 * Thank you for confirming. I’ll put this in as a fix for the next version.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Warning: array_key_exists() expects parameter 2 to be array’ is closed
to new replies.

 * ![](https://ps.w.org/top-10/assets/icon-256x256.png?rev=2986432)
 * [WebberZone Top 10 — Popular Posts](https://wordpress.org/plugins/top-10/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/top-10/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/top-10/)
 * [Active Topics](https://wordpress.org/support/plugin/top-10/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/top-10/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/top-10/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Ajay](https://wordpress.org/support/users/ajay/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/warning-array_key_exists-expects-parameter-2-to-be-array-2/#post-6111131)
 * Status: resolved