We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7231
    • 4,205 Posts
    Which is better to use ifelse or if else? Are they the same?
      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

      Something is happening here, but you don't know what it is.
      Do you, Mr. Jones? - [bob dylan]
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      No, they’re not the same, but I can’t make heads nor tails of exactly what the difference is...

      In PHP, you can also write ’else if’ (in two words) and the behavior would be identical to the one of ’elseif’ (in a single word). The syntactic meaning is slightly different (if you’re familiar with C, this is the same behavior) but the bottom line is that both would result in exactly the same behavior.

      If you’re coming from another language that does not have the "elseif" construct (e.g. C++), it’s important to recognise that "else if" is a nested language construct and "elseif" is a linear language construct; they may be compared in performance to a recursive loop as opposed to an iterative loop...This test should show that "elseif" executes in roughly two-thirds the time of "else if".

      I think it’s a case of a difference that really doesn’t make much of a difference.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 7231
        • 4,205 Posts
        That is good information, it really clears it up for me shocked I think that bottom line is that elseif is better. From what I understand the else if are actually two commands so it will take longer than elseif to process. I makes sense. Thanks for clearing that up.
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don't know what it is.
          Do you, Mr. Jones? - [bob dylan]