我已经将我的PHP版本更新到7.4,之后这个错误开始显示。错误显示在选项中,在<所选标记,即使在页面刷新后我也要尝试维护数据。
<?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或$categors为null或不是数组。请尝试以下操作以显示哪一个不是数组var_dump($posts); var_dump($categs);
您可以使用is_array 测试阵列