Folks,
Q1.
How to findout if an array exists or not ?
Q2.
And, how to findout if an array is empty or not ?
Talking about non-key value arrays, like the ones shown above.
Q3.
I use the following 'Set A' codes to findout if array is empty of values or not. Are these codes ok or not ? If not then why not ?
Set A: 1
If($array)
{
echo 'array full';
}
Set A: 2
If(!$array)
{
echo 'array empty';
}
Set A: 3.
If(empty($array))
{
echo 'array full';
}
Set A: 4.
If(!empty($array))
{
echo 'array empty';
}
Set A: 5.
If(empty($array) == FALSE)
{
echo 'array empty';
}
Set A: 6.
If(empty($array) == 'FALSE')
{
echo 'array empty';
}
Set A: 7.
If(empty($array) == "FALSE")
{
echo 'array empty';
}
I reckon all followings are wrong:
Notice the closing brackets and operator on each example.
Q4. Are all these wrong or not to findout if an array is empty of values or not ?
Set B: 1
If(empty($array == FALSE))
{
echo 'array empty';
}
Set B: 2
If(empty($array == 'FALSE'))
{
echo 'array empty';
}
Set B: 3
If(empty($array == "FALSE"))
{
echo 'array empty';
}
Set B: 4
If(empty($array) = FALSE)
{
echo 'array empty';
}
Set B: 5
If(empty($array) = 'FALSE')
{
echo 'array empty';
}
Set B: 6
If(empty($array) = "FALSE")
{
echo 'array empty';
}
Set B: 7
If(empty($array = FALSE))
{
echo 'array empty';
}
Set B: 8
If(empty($array = 'FALSE'))
{
echo 'array empty';
}
Set B: 9
If(empty($array = "FALSE")
{
echo 'array empty';
}
Show me which ones you prefer over the others to findout if an array is empty or not.
Give your rankings to all the code samples I mentioned so I can see which method you prefer.
Thanks