无法修复“期望参数2为数组,null给定”错误
I have this errors in my code. Can someone help me?
Warning: array_reduce() expects parameter 1 to be array, null given in /srv/disk1/2317571/www/loquium.atwebpages.com/wp-content/themes/foodica/functions/customizer/helpers-fonts.php on line 506
Warning: array_key_exists() expects parameter 2 to be array, null given in /srv/disk1/2317571/www/loquium.atwebpages.com/wp-content/themes/foodica/functions/customizer/helpers-fonts.php on line 192
Warning: array_key_exists() expects parameter 2 to be array, null given in /srv/disk1/2317571/www/loquium.atwebpages.com/wp-content/themes/foodica/functions/customizer/helpers-fonts.php on line 192
Warning: array_key_exists() expects parameter 2 to be array, null given in /srv/disk1/2317571/www/loquium.atwebpages.com/wp-content/themes/foodica/functions/customizer/helpers-fonts.php on line 192
Warning: array_key_exists() expects parameter 2 to be array, null given in /srv/disk1/2317571/www/loquium.atwebpages.com/wp-content/themes/foodica/functions/customizer/helpers-fonts.php on line 192
Warning: array_key_exists() expects parameter 2 to be array, null given in /srv/disk1/2317571/www/loquium.atwebpages.com/wp-content/themes/foodica/functions/customizer/helpers-fonts.php on line 192
Line 190 - 196
// Verify that the font exists
if ( array_key_exists( $font, $allowed_fonts ) ) {
// Build the family name and variant string (e.g., "Open+Sans:regular,italic,700")
$family[] = urlencode( $font . ':' . join( ',', foodica_choose_google_font_variants( $font, $allowed_fonts[ $font ]['variants'] ) ) );
}
}
Line 503 - 506
$transient = json_decode($transient, true);
$transient = array_reduce($transient['items'], 'foodica_transform_google_fonts_array', array());
return apply_filters('foodica_get_google_fonts_from_api', $transient);
}
endif;
我的代码中出现此错误。 有人可以帮助我吗? p>
警告:array_reduce()期望参数1为数组,在 /srv/disk1/2317571/www/loquium.atwebpages中给出null 第506行上的.com / wp-content / themes / foodica / functions / customizer / helpers-fonts.php p>
警告:array_key_exists()期望参数2为数组,null \ n在第192行的 /srv/disk1/2317571/www/loquium.atwebpages.com/wp-content/themes/foodica/functions/customizer/helpers-fonts.php 中给出 p>
警告:array_key_exists()期望参数2为数组,null 在 /srv/disk1/2317571/www/loquium.atwebpages.com/wp-content/themes/foodica/functions/customizer/helpers中给出 第192行-fonts.php p>
警告:array_key_exists()期望参数2为数组,null 在 / srv / disk1 / 2317571 / www / loquium中给出。 第192行的atwebpages.com/wp-content/themes/foodica/functions/customizer/helpers-fonts.php p>
警告:array_key_exists()期望参数2为数组,null 给予我 第192行n /srv/disk1/2317571/www/loquium.atwebpages.com/wp-content/themes/foodica/functions/customizer/helpers-fonts.php p>
警告:array_key_exists()期望参数2为数组,null 在 /srv/disk1/2317571/www/loquium.atwebpages.com/wp-content/themes/foodica/functions/customizer/helpers-fonts中给出 第192行.php p> blockquote>
第190 - 196行 p>
//验证字体是否存在 n if(array_key_exists($ font,$ allowed_fonts)){ //构建姓氏和变体字符串(例如,“Open + Sans:regular,italic,700”) $ family [] = urlencode($ font 。 ':'。 join(',',foodica_choose_google_font_variants($ font,$ allowed_fonts [$ font] ['variants']))); } } code> pre>
Line 503 - 506 p>
$ transient = json_decode($ transient,true); $ transient = array_reduce($ transient ['items'],'foodica_transform_google_fonts_array',array() ); 返回apply_filters('foodica_get_google_fonts_from_api',$ transient); } endif; code> pre> div>
Just use typecasting as shown below:
array_key_exists( $font, (array) $allowed_fonts );