Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

363
Views
Why use : instead of { in if statements

Why do people use

if(condition) :
    /*do something*/
else:
    /*do something else*/
endif;

instead of

if(condition) 
{
    /*do something*/
} 
else
{
    /*do something else*/
}

Is one better than the other in any way? What should i get use to too?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This falls in the category of coding style. Some people like to use brackets some like to use the ":end..." notation. The advantage to the latter is more towards using PHP conditionals and loops where there is output to HTML. For example,

//Pure PHP with brackets
<?php
if ($condition) {
   echo "output";
}?>

//PHP and HTML with brackets
<?php
if ($condition) {?>
   output
<?php } ?>

//PHP and HTML with ":end..." notation
<?php if ($condition):?>
   output
<?php :endif ?>

Some people prefer the last as the ":endif" gives a clue what opening construct to look for when matching control structures. The bracket could match any other bracket but an ":endif" can only match and "if" construct. You can use either it is up to your style.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!