faqts : Computers : Programming : Languages : PHP : Language and Syntax : General : Variables

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 4 people (100%) answered Yes
Recently 4 of 4 people (100%) answered Yes

Entry

What are the % for ? I often found those in notation like %s or %d.

Jul 16th, 2001 11:59
Rich Cavanaugh, Alain de Nemours,


The % is used in the various printf() functions. It's used to format 
text. See http://php.net/manual/en/function.sprintf.php that describe 
this syntax.
for example:
<?php
    printf("%01.2f", 1234.1234);
?>
will output:
1234.12
The ? is the ternary operator and is described on 
http://php.net/manual/en/language.expressions.php
for example:
<?php
    echo ((TRUE)?('true!!!'):('false!!!'));
?>
will output:
true!!!