Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Syntax question from a beginner

 
   Database Forums (Home) -> PHP RSS
Next:  TechTips: Handling "logging in" in Para..  
Author Message
Brad Blanchard

External


Since: Aug 11, 2004
Posts: 2



(Msg. 1) Posted: Wed Aug 11, 2004 12:54 pm
Post subject: Syntax question from a beginner
Archived from groups: alt>php (more info?)

I'm using L. Welling and L. Thomson's book to start learning PHP.
I have two syntax questions which they don't explain:

1) in the code:

echo 'Subtotal: $'.number_format($totalamount,2).'<br />';

I suppose that the first period is to concantenate the 'Subtotal'
string to the totalamount variable, and that the last one is to
concantenate the totalamount variable to the html tag. But why is
the dollar sign inside the first string? What is its purpose?

2) I know Pascal and can understand most of what is going on in
the C-like syntax, but the following line is Greek to me (and not
explained in the book). What do the question mark and the
double-colon mean? How do you read this statement?

echo ($char=="\n" ? '<br />': $char);

TIA,
--
Brad Blanchard
Website: http//www.braser.com
email accepted from the website

 >> Stay informed about: Syntax question from a beginner 
Back to top
Login to vote
steve




Joined: Jan 06, 2004
Posts: 660



(Msg. 2) Posted: Thu Aug 12, 2004 2:13 am
Post subject: Re: Syntax question from a beginner [Login to view extended thread Info.]

Brad Blanchard wrote:
I'm using L. Welling and L. Thomson's book to start learning PHP.
I have two syntax questions which they don't explain:

1) in the code:

echo 'Subtotal: $'.number_format($totalamount,2).'<br />';

I suppose that the first period is to concantenate the 'Subtotal'
string to the totalamount variable, and that the last one is to
concantenate the totalamount variable to the html tag. But why is
the dollar sign inside the first string? What is its purpose?



TIA,


Brad, the $ sign is there, so that the amount will be shown with $ sign on the left of the amount.

Quote:
2) I know Pascal and can understand most of what is going on in
the C-like syntax, but the following line is Greek to me (and not
explained in the book). What do the question mark and the
double-colon mean? How do you read this statement?

echo ($char=="\n" ? '<br />': $char);


That is a short-hand conditional $x ? $a : $b;
means if $x is true, then return $a else return $b.

 >> Stay informed about: Syntax question from a beginner 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
some beginner question :) - I want to write php scripts which will be using some classes, let's say following class aClass: include('config.php'); class aAclass { public x,y; function __construct($a,$y) {$this->x=$x;$this->y=$y;} function appendToFile() { ....

Best Beginner PHP Editor? - What is the best beginner PHP editor that is freeware? I need something that will highlight an error if the code is wrong. Any help would be appreciated. Hoops

Short syntax for array in PHP - Hello, is there a shorter syntax for array beside array("one", "two"), something link {"one", "two"}? cheers sebastian

Page Last Updated Syntax error - I tried embedding this in an XHTML file, then changed it to a last4.php, but get a syntax error. What am I doing wrong? <?php $last_modified = filemtime("last4.php"); print("Page Last Updated: "); print(date("m/j/y h:i"...

my cron jobs can not use SELECT INTO OUTFILE syntax? - just quick wrote this shell script to be called by cron: #!/usr/bin/php5 <?php $link = mysql_connect('localhost', 'xxxxxx', 'xxxxxxx'); if (!$link) { die('Not connected : ' . mysql_error()); } // make foo the current db $db_selected =..
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]