webdevask.com

Menu

  • Home
  • New
  • Add question

php - Handling 'Undefined array key' warnings in PHP8

View Original

This question already has answers here:

Answer

Solution:

If you're happy to do some find-and-replace, there are a few constructs which guarantee the same behaviour but without the Warning.

The most universal is the , which lets you convert an unset array key into an explicit null:

if ($_POST['submit']??null) { ... } else { ... }
<input value="<?=$this_page['id']??null?>"> 

More logically, the default in an echo statement is an empty string:

<input value="<?=$this_page['id']??''?>"> 

The logical default in an if statement is a boolean false, but perhaps more readable is the :

if (! empty($_POST['submit'])) { ... } else { ... }

Source

See also:

  • php สร้าง Google ชีตจากบัญชีบริการ

  • php - Laravel 8.0 Installation Failed

  • javascript - How to include HTML data (tags) as value in "arrayToDataTable" of Google Pie Chart?

  • how to Grouping array in php

  • php - vender folder from my laravel project has more 1k error

© 2021
E-mail: contact@webdevask.com
Back to top