Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5937511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:33:07+00:00 2026-05-22T15:33:07+00:00

<? switch ($var): ?> <? case 1: ?> It’s 1! <? break ?> <?

  • 0
<? switch ($var): ?>
  <? case 1: ?>
    It's 1!
  <? break ?>
<? endswitch ?>

I want to do something like that, in other words use the switch statement in PHP templates. This is possible with the if statement. The above code generates Parse error: syntax error, unexpected T_INLINE_HTML, expecting T_ENDSWITCH or T_CASE or T_DEFAULT in PHP 5.3. The PHP docs suggests that this should be possible.

Can someone confirm that this doesn’t work, or rather, tell me what I’m doing wrong?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:33:08+00:00Added an answer on May 22, 2026 at 3:33 pm

    I read in the php doc that your example should not work.

    Any output (including whitespace) between a switch statement and the
    first case will result in a syntax error. For example, this is invalid

    Try this instead:

    <div>
    <?php switch($variable): 
    case 1: ?>
        <div>
        Newspage
        </div>
    <?php break; ?>
    <?php case 2: ?>
        </div>
        Forum
        <div>
    <?php break; ?>
    <?php endswitch; ?>
    </div>
    

    http://php.net/control-structures.alternative-syntax

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following two snippets, with braces: switch (var) { case FOO: { x
I need to declare the query variable outside the switch statement that way I
Switch statement fallthrough is one of my personal major reasons for loving switch vs.
When writing a switch statement, there appears to be two limitations on what you
Is that possible to switch an Open Source Project license from GPL to LGPL
Management wants us to switch to Infragistics. But my boss says that any 3rd
I have this code: var str = $(#datepicker).datepicker(getDate); var datestr = str.toString().split( ); switch(datestr[1])
Switch statements are typically faster than equivalent if-else-if statements (as e.g. descibed in this
I can switch between windows with C-x o, but if I have opened multiple
Since our switch from Visual Studio 6 to Visual Studio 2008, we've been using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.