|
Author: Jenny Nguyen
|
|
An empty array can cause your software to crash or stop the website to functions correctly. You can check an array value to see if it is empty or null before accessing it so that your site won't have an error. Here's how: 1. Before access the array value, use isset or empty function. Sample code: Empty Function if(empty($lising)){ Isset function if(isset($listing)){ You could also use the count function see if there has been any item added to the array. See example below.
if( count($yourarray) && empty($listing['feature']) )
{
//Perform your code
}
To check just for a single element: if(!empty($listing['feature'])) //This element is not empty. } Did you like this tip?
|