1

I have this:

<?php echo implode("<th></th>", $days); ?> 

Although, that outputs:

Today<th></th>02-03<th></th>01-03<th></th>29-02<th></th>28-02<th></th>27-02<th></th>26-02 

As you can see, the <th> and </th> is not formatted correct, as I want to have the date ($days) variable in between them like this <th>Today</th><th>02-03</th> and so on...

How can I obtain this?

2
  • it is formatted correct. if you want to add some tags to the resulting string, you may add them. Commented Mar 3, 2012 at 12:49
  • implode works correctly, just not the way you want it to ;) Commented Mar 3, 2012 at 12:50

3 Answers 3

5

Flip the order of your separator, then add the surrounding tags.

<?php echo "<th>" . implode("</th><th>", $days) . "</th>"; ?> 
Sign up to request clarification or add additional context in comments.

Comments

5
  <?php  foreach( $days as $day ) 
        echo "<th>$day</th>";
  ?>

Comments

0
<?php echo "<th>" . implode("</th><th>", $days) ."</th>"; ?> 

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.