Joseph Longo
asked on
Concatenate When Condition Is Met
Hello experts,
Here is my code:
Here is my code:
<input type="checkbox" name="seat_rented[]" value="<?php echo $row['seat_serial'];?>">
$n = count($seat);
foreach($seat as $x) {
$pdf-> Write(0, $x . ", ");
}
I only want to concatenate the comma when $n is >1. If $n equals 1, I want to concatenate a period. I can't think of the if or while statement to handle this...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was unable to get the for loop working correctly, for whatever reason. However, the implode function worked correctly. Thank you for your assistance.
ASKER
@HainKurt
The implode function worked correctly, with the exception of modifying it like this:
$pdf-> Write(0, implode(", ", $seat));
I am using FPDF to generate PDF documents.
The implode function worked correctly, with the exception of modifying it like this:
$pdf-> Write(0, implode(", ", $seat));
I am using FPDF to generate PDF documents.
The implode function worked correctly, with the exception of modifying it like this:
yes, implode joins all items with delimiter provided... no need to loop or check first or last item to put delimiter or not... implode does all for you... because I could not get what pdf write function is, I left the syntax to you to fix :)
Open in new window
not sure what those 3 parameters are, but you can fix line 4 & 6 as you wish