I am working with laravel framework project and facing below issue.
Query:
$query = DB::table('test');
$query->select('*');
$query->where('testId = 1');
$result = $query->get();
print_r($result);
Output :
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
)
)
Now I am checking $result have record or not.
if(empty($result))
{
echo "Not Empty check with empty()";
}
if(count($result) == 0)
{
echo "Not Empty check with count()";
}
Output:
Not Empty check with count()
Question :
I have used empty() in all the projects but in laravel framework project I am not able to know that why this $result going in count() condition and not going in empty().
Note:
I have read that count() is slow compare to empty() also empty() check variable is set or not so I am using empty() in all return array or object array.
Please help someone.
Thanks in advance!