PHP – Check If Array Element is Null
Hi guys, in this short tutorial, we will see how can we check in PHP If Array Element is Null or not. So let’s get started.
To check if an element in an array is null in PHP, you can use the isset()
function. This function returns true
if the variable is set and is not null, and false
if the variable is not set or is null.
Here is an example of how you can use isset()
to check if an element in an array is null:
$array = ['foo', 'bar', null, 'baz']; if (isset($array[2])) { // The element at index 2 is not null } else { // The element at index 2 is null }
You can also use the is_null()
function to check if a value is null. This function returns true
if the value is null, and false
if it is not.
$array = ['foo', 'bar', null, 'baz']; if (is_null($array[2])) { // The element at index 2 is null } else { // The element at index 2 is not null }
Note that isset()
will return false
if the element is not set or is null, while is_null()
will return true
only if the element is null.
Check Out More Resources:
Articles:
Website: https://laravelplug.com/
YouTube Channel: https://www.youtube.com/channel/UCnTxncHQcBSNs4RCuhWgF-A?sub_confirmation=1
WordPress Playlist: https://www.youtube.com/watch?v=8VvXzFAFwQU&list=PLVoVZqAh8dTLHZ51egvEU7dsOrRCSIMWx
Tools Playlist: https://www.youtube.com/watch?v=gTQoUn3BQkM&list=PLVoVZqAh8dTK-DWHBGWOEEvzvPQrgFne-
WordPress Tutorials: https://laravelplug.com/category/wordpress/
Laravel Tutorials: https://laravelplug.com/category/laravel/
PHP Tutorials: https://laravelplug.com/category/php/
SQL Tutorials: https://laravelplug.com/category/sql/
Various Tips: https://laravelplug.com/category/tips/
Useful Tools: https://laravelplug.com/category/tools/
Socials:
Twitter: https://twitter.com/LaravelPlug
Pinterest: https://www.pinterest.com/LaravelPlugCom/
Facebook: https://www.facebook.com/groups/1020759861842360
Mail: info@laravelplug.com
#laravel #guide #php