array_key_exists() expects parameter 2 to be array

14.3k Views Asked by At

My Wordpress page (yarnhk.com) appears the following lines:

Warning: array_key_exists() expects parameter 2 to be array, string given in /home/yarnhrnm/public_html/wp-content/plugins/fusion-core/shortcodes/class-fullwidth.php on line 482

Warning: array_key_exists() expects parameter 2 to be array, string given in /home/yarnhrnm/public_html/wp-content/plugins/fusion-core/shortcodes/class-fullwidth.php on line 483

The fullwidth.php file line 482 & 483 show as follows:

if ( ( array_key_exists( 'backgroundattachment', $args ) 
   && $args['backgroundattachment'] == 'scroll' ) 
   || ( array_key_exists( 'background_attachment', $args ) 
   && $args['background_attachment'] == 'scroll' )

Any help here?

2

There are 2 best solutions below

1
On

parameter 2 to be array, string given

The error message says, that your $args is not an array but a normal string. Look for the definition of the variable (and - of course - for any accident overwriting).

You should use var_dump($args); to output the type and the value of $args.

0
On

Finally, I have made it with the following codes:

if( is_array($args) && ( array_key_exists( 'backgroundattachment', $args ) && $args['backgroundattachment'] == 'scroll' ) || is_array($args) && ( array_key_exists( 'background_attachment', $args ) && $args['background_attachment'] == 'scroll' )) { 
    // Something
}

Done!