Jump to content


Photo

noob questions about using $disp


  • Please log in to reply
4 replies to this topic

#1 lordvader

lordvader
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 18 June 2006 - 01:21 AM

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

#2 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 18 June 2006 - 01:29 AM

$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.
[table]



Don't worry, the printer fairies will sort it out.

#3 lordvader

lordvader
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 18 June 2006 - 02:04 AM

And that's totally enough!

Thanks Fyorl

#4 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 18 June 2006 - 02:42 AM

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.
$a .= $b;
$a = $a + $b
//strings only!
And the rest are for numbers:
$a += $b;
$a = $a + $b;
$a -= $b;
$a = $a - $b;
$a *= $b;
$a = $a * $b;
$a /= $b;
$a = $a / $b;

http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#5 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 18 June 2006 - 02:54 AM

[!--quoteo(post=385211:date=Jun 17 2006, 09:42 PM:name=neylitalo)--][div class=\'quotetop\']QUOTE(neylitalo @ Jun 17 2006, 09:42 PM) View Post[/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.
$a .= $b;
$a = $a + $b
//strings only!
And the rest are for numbers:
$a += $b;
$a = $a + $b;
$a -= $b;
$a = $a - $b;
$a *= $b;
$a = $a * $b;
$a /= $b;
$a = $a / $b;
[/quote]

$a .= $b;
// Is actually a shortcut for
$a = $a . $b;
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.
[table]



Don't worry, the printer fairies will sort it out.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users