I am checking $_POST arrays, but I cannot find a way to check whether the array is empty. Does anyone know how I can check this. I have tried !empty()
and isset()
, but both ways returning true.
My HTML form with a select box, text field and submit button:
<form method="post">
<select name="product_name[]">
<option value="Camera">Camera</option>
<option value="Radio">Radio</option>
<option value="Television">Television</option>
</select>
<input name="product_price[]" />
<input type="submit" name="submit">
</form>
My PHP:
if( ! empty( $_POST['product_name'] ) && ! empty( $_POST['product_price'] ) ) {
print_r( $_POST['product_name'] );
print_r( $_POST['product_price'] );
}
Return:
Array ( [0] => Camera )
Array ( [0] => )