I want to implode the multi array inside the for loop.
$_POST['PprodName'];
In this $_POST['PprodName']
I have got a value as:
Array ( [0] => steel mj23 [1] => [2] => [3] => [4] => [5] => [6] => [7] => )
steel mj23
is my first product name.
Now I want to check if the element is empty according to their position. so I applied a for loop but don't know how to implode element's which are not empty.
I want to implode only those element which are not empty.
Here is my for loop.
for( $i=0; $i < count($_POST['PprodName']); $i++ ) {
if( !empty( $_POST['PprodName'][$i] ) ) {
print_r($_POST['PprodName'][$i]);
}
}
You don't need a for loop. Simply filter all empty values with array_filter()
out and then you can simply use implode()
, like this:
echo implode(", ", array_filter($_POST['PprodName']));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With