This question already has an answer here:
I have an associative array of id. In the controller I want to check if the array received is empty or not. I have written the following code for it but it does not work.
$product1=$_POST['id'];
$productString = implode(" ",$product1);
echo $productString;
if(is_null($productString)){
echo "No Values";
}else {
echo "Values are present";
}
I have tried with empty() as well but in all the case even if there are no values in the array, which I am converting into a string, it says values are present. There are 5 fixed rows in my table in the view file, so, even if the values are empty the array output shows
Array (
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
)
Any help is welcome.
</div>