Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ":" mean in PHP? [duplicate]

Tags:

Possible Duplicate: What is “:” in PHP?

What does the : mean in the following PHP code?

<?php     while (have_posts()) : the_post(); ?> 
like image 374
Paulo Coghi Avatar asked Jan 20 '11 13:01

Paulo Coghi


People also ask

What does &$ mean in PHP?

It means you pass a reference to the string into the method. All changes done to the string within the method will be reflected also outside that method in your code.

What does this -> mean in PHP?

The object operator, -> , is used in object scope to access methods and properties of an object. It's meaning is to say that what is on the right of the operator is a member of the object instantiated into the variable on the left side of the operator. Instantiated is the key term here.

What does => mean in PHP array?

=> is the separator for associative arrays. In the context of that foreach loop, it assigns the key of the array to $user and the value to $pass .

What does AT symbol mean in PHP?

Concatenation of two strings in PHP.


1 Answers

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; } 
like image 51
ircmaxell Avatar answered Nov 03 '22 09:11

ircmaxell