Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/12273-noob-questions-about-using-disp/
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.
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]
[!--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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.