Il existe plusieurs méthodes pour vérifier si un tableau PHP, du type array
, est vide :
- La fonction PHP
empty()
.
- La fonction PHP
count()
.
- La fonction PHP
sizeof()
.
Vérifier si un tableau est vide avec la fonction empty()
:
<?php
$tableau = array();
if(empty($tableau))
{
echo "Le tableau est vide";
}
?>
Vérifier si un tableau est vide avec la fonction count()
:
<?php
$tableau = array();
if(count($tableau) == 0)
{
echo "Le tableau est vide";
}
?>
Vérifier si un tableau est vide avec la fonction sizeof()
:
<?php
$tableau = array();
if(sizeof($tableau) == 0)
{
echo "Le tableau est vide";
}
?>