簡體   English   中英

嘗試訪問值類型為 null 的數組偏移量

[英]Trying to access array offset on value type of null on a

我已將 PHP 版本更新為 7.4,此錯誤此后開始顯示。 錯誤顯示在選項中,在 <selected 標記中,當我即使在頁面刷新后也嘗試維護數據時。

<?PHP
     $posts = filter_input_array(INPUT_POST, FILTER_DEFAULT);
?>
<form method="post" name="create_posts">
<label>Categories available</label>
<select name="category_id" class="select_list">
  <option value="null">Pick a category: </option>

<?PHP
     $readCategs= new Read();
     $readCategs->query("SELECT DISTINCT ca.id AS cat_id,
                                      ca.title AS title, ca.content AS content
                                      FROM categories ca LEFT JOIN posts p ON p.cat_id = ca.id
                                        ORDER BY title ASC");
                            //var_dump($readCategs);
     if(!$readCategs->getResult()):
       echo "<a href='create_category'><option disabled='disabled'>
         There are no categories</option></a>";
     else:
       foreach($readCategs->getResult() AS $categs):
         echo "<option value=\"{$categs['cat_id']}\" class='options' ";
           if($posts['category_id'] == $categs['cat_id']):
             echo 'selected="selected" ';
           endif;
         echo ">{$categs['title']}</option>";
       endforeach;
     endif;
?>
</select>
</form>````        

The error shows on the "if($posts['category_id'] == $categs['cat_id']):" line

傾向於建議 $posts 或 $categs 為空或不是數組。 嘗試以下以顯示哪個不是數組var_dump($posts); var_dump($categs); var_dump($posts); var_dump($categs);

您可以使用 is_array 測試數組

暫無
暫無

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

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