0

I want to create dropdown programmatically. The dropdown have time and at last I want in option close. Kindly check what I am doing:

<select>
     <?php for($i = 0; $i < 24; $i++): ?>
      <option value="<?= $i; ?>"><?= $i % 12 ? $i % 12 : 12 ?>:00 <?= $i >= 12 ? 'PM' : 'AM' ?></option>
      <?php endfor ?>
</select>

This gives me the time what I want like 1:00 Am 2:00 AM

But I want at last the option "close" will show. Because office will close on sunday. I am getting the numbers programatically but at last I want user is able to select close option as well.

Any idea or suggestions would be welcome.

1
  • You shouldn't nest ternary's inside of eachother, it makes it hard to read. Commented Oct 18, 2018 at 12:54

1 Answer 1

1

You could just do the following, this will add the close option after your code has added the hours:

<select>
  <?php for($i = 0; $i < 24; $i++): ?>
    <option value="<?= $i; ?>"><?= $i % 12 ? $i % 12 : 12 ?>:00 <?= $i >= 12 ? 'PM' : 'AM' ?></option>
  <?php endfor ?>
  <option value="close">Close</option>
</select>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.