Tuesday, 30 May 2017

syntax - What does ":" mean in PHP?





Possible Duplicate:
What is “:” in PHP?






What does the : mean in the following PHP code?



    while (have_posts()) : the_post();
?>

Answer



It's called an Alternative Syntax For Control Structures. You should have an endwhile; somewhere after that. Basically, it allows you to omit braces {} from a while to make it look "prettier"...



As far as your edit, it's called the Ternary Operator (it's the third section). Basically it's an assignment shorthand.



$foo = $first ? $second : $third;


is the same as saying (Just shorter):



if ($first) {
$foo = $second;
} else {
$foo = $third;
}

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...