Skip to content

PHP Guru's......

Featured Replies

I've got a php script for processing a html form.

Works fine.

Checkbox values translated into an array and then churn into an email.

But, it simply lists the values in the email (though the email does include text to give some form and value to what the form says.

But, is it possible to put a count in so that in the last value of the array, it puts the word "and" in, so it's grammatically correct in language?

For example, rather than saying "interested in option 1, option2, option 5" it will say "interested in option 1, option2 AND option 5"

for ($i = 0; $i < count($array)-1; $i++) {
  echo $array['$i'] .", ";
}
echo " and " . $array(count($array));

  • Author

I had a version that worked on self-processing the array,"services", but wasn't wanting to play in an e-mailed response.

Now duly implemented as follows, with a nice little addition to add some proper grammar too.

$formatted_services = "";

for($i = 0; $i < sizeof($services); $i++) {

if($i == sizeof($services)-1 && sizeof($services) != 1)

$formatted_services .= "and $services[$i]";

else if(sizeof($services) == 1)

$formatted_services = $services[$i];

else

$formatted_services .= "$services[$i], ";

Yeah OK Mr. Picky :P

  • Author
Yeah OK Mr. Picky :P

Wasn't anything wrong with the offered code, actually more compact.

And it's Mr Pedantic, not Picky....:P

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Important Information

Welcome to BRISKODA. Please note the following important links Terms of Use. We have a comprehensive Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.