2
Due to a system need we are working on, I need to send 3 fields as an array to a PHP. Example:
<input type="text" name="name[]" />
<input type="text" name="name[]" />
<input type="text" name="name[]" />
What happens is that even if I select only one, it brings the reported result and the other blank. And the Count of the array always returns 3:
Teste DIEGO . Fim
Teste . Fim
Teste . Fim
How could I treat the array to only have the data actually informed? I display it this way (by testing):
foreach( $name as $key => $n ) {
print "Teste ".$n.". Fim<br>";
}
use
empty()
inside the foreach.– rray
Can you show me?
– Diego
if(!empty($n)){echo $n .'<br>'}else{ echo 'valor em branco';}
I believe that’s it.– rray
I believe that if you do so it works: foreach($name as $key => $n){ if($name[$key] == ""){ unset($name[$key) ; }
– Ericks Rodrigues
@rray, your answer worked, but Wallace Maxters got "better" because it comes straight in the post. Thanks!
– Diego