Jump to content

Archived

This topic is now archived and is closed to further replies.

lordvader

noob questions about using $disp

Recommended Posts

I'm learning php bit by bit, as my needs arise. I've come across $disp, but am unsure of a few things:

What is the difference with
$disp .=

and

$disp =


Also, in relation to $disp, what is "\t and \n" and what are the proper uses?


Or you could just tell me what category in php that stuff falls under, and I'll look it up myself

Thanks

Share this post


Link to post
Share on other sites
$disp is a variable. It stores pretty much anything you put in it. A variable can be anything beginning with a letter or underscore followed by any number of other letters, numbers or underscores. $disp isn't special in any way the same as $foo and $bar aren't (even if you see them a lot).

$disp =
will put a value in the variable like:
$disp = 'a string';

then if you were to do
$disp .= ' is cool';

and then
echo $disp;
you would see: a string is cool

You can also put numbers in ($disp = 2456729). The two main methods of storing strings is with single quotes and double quotes. Single quotes are very literal so $disp = '\n' would print just that but $disp = "\n"; would be seen as a newline character.

That's a basic overview, there's plenty of documentation about.

Share this post


Link to post
Share on other sites
PHP has several little shortcuts built in (as do most programming languages); I'll put the shortcut on top, and the long version on the bottom.
[code]$a .= $b;
$a = $a + $b
//strings only![/code]
And the rest are for numbers:
[code]$a += $b;
$a = $a + $b;[/code]
[code]$a -= $b;
$a = $a - $b;[/code]
[code]$a *= $b;
$a = $a * $b;[/code]
[code]$a /= $b;
$a = $a / $b;[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=385211:date=Jun 17 2006, 09:42 PM:name=neylitalo)--][div class=\'quotetop\']QUOTE(neylitalo @ Jun 17 2006, 09:42 PM) [snapback]385211[/snapback][/div][div class=\'quotemain\'][!--quotec--]
PHP has several little shortcuts built in (as do most programming languages); I'll put the shortcut on top, and the long version on the bottom.
[code]$a .= $b;
$a = $a + $b
//strings only![/code]
And the rest are for numbers:
[code]$a += $b;
$a = $a + $b;[/code]
[code]$a -= $b;
$a = $a - $b;[/code]
[code]$a *= $b;
$a = $a * $b;[/code]
[code]$a /= $b;
$a = $a / $b;[/code]
[/quote]

[code]$a .= $b;
// Is actually a shortcut for
$a = $a . $b;[/code]
Javascript uses + to concatenate strings, PHP uses '.'. Using the + operator on strings is possible in PHP as PHP will turn '15' into 15 for the purpose of the calculation but if it is not a number, the ASCII key code gets used I seem to recall.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.