簡體   English   中英

如何修復嘗試訪問 bool 類型值的數組偏移量

[英]How to fix Trying to access array offset on value of type bool in

在 PHP 7.4 中,我收到此通知: Trying to access array offset on value of type bool in

if( $book_font ){
   foreach ( $book_font as $key => $font ) {
      if ( in_array( $font['face'], $all_google_fonts ) ) {
         self::options_typography_enqueue_google_font( $font['face'] );    
      }
   }
}

此行的注意事項:

if ( in_array( $font['face'], $all_google_fonts ) ) { 

該錯誤意味着在foreach循環中, $font的一個或多個值是 boolean 而不是數組。

解決它的一種方法是使用null 合並運算符?? 像這樣:

if ( in_array( $font['face'] ?? '', $all_google_fonts ) ) { 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM