ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: PHP :: PHP ±äÁ¿

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

PHP
WINDOWSϰ²×°MyS..
PHP ÖÆ×÷ ÍøÕ¾/·þ..
ÓÃPHPºÍCSSÖÆ×÷»î..
PHP µ¥¼þģʽ
PHP MVCģʽ£¬Àà·..
PHP ÖÐʹÓÃÕýÔò±í..
PHP ·ÀÖ¹ SQL ×¢È..
PHP ¿çÕ¾µã½Å±¾¹¥..
PHP ·ÀÖ¹Óû§²Ù×Ý..
PHP ·ÀÖ¹Ô¶³Ì±íµ¥..

PHP ±äÁ¿


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-28 ÐÞ¸Ä:2007-06-18 ä¯ÀÀ:8247 :: ::

Variables are used for storing values, such as numbers, strings or function results, so that they can be used many times in a script.
“±äÁ¿”ÊÇÓÃÀ´´æ´¢“Öµ”µÄ£¬È磺Êý×Ö£¨number£©¡¢×Ö·û´®£¨string£©»òÕߺ¯Êý½á¹û£¨function results£©£»Ëü¿ÉÒÔÔڽű¾ÖÖÖØ¸´Ê¹Óá£


Variables in PHP
PHP±äÁ¿

All variables in PHP start with a $ sign symbol. Variables may contain strings, numbers, or arrays.
ËùÓеÄPHP±äÁ¿µÄÇ°Ãæ¶¼°üº¬Ò»¸ö“$”·ûºÅ¡£±äÁ¿¿ÉÒÔ°üº¬×Ö·û´®¡¢Êý×Ö¡¢Êý×é¡£

Below, the PHP script assigns the string "Hello World" to a variable called $txt:
ÏÂÃæµÄ°¸ÀýÖУ¬ÎÒÃÇÏȸø“txt”¸½Ò»¸ö×Ö·û´®“Hello World”£¬È»ºóÔÙÏÔʾÕâ¸ö“txt”±äÁ¿£º

<html>
<body>
<?php
$txt="Hello World";
echo $txt;
?>
</body>
</html>

To concatenate two or more variables together, use the dot (.) operator:
Èç¹ûÄãÏë°ÑÁ½¸ö±äÁ¿ºÏ¶þΪһ£¬ÄãÐèҪʹÓã¨.£©²Ù×÷·û£¬¾ßÌåÈçÏ£º

<html>
<body>
<?php
$txt1="Hello World";
$txt2="1234";
echo $txt1 . " " . $txt2 ;
?>
</body>
</html>

The output of the script above will be: "Hello World 1234".
ÉÏÊöÀý×ÓÊä³öµÄ½á¹ûÊÇ£º"Hello World 1234"


Variable Naming Rules
±äÁ¿ÃüÃû¹æÔò

  • A variable name must start with a letter or an underscore "_"
    Ò»¸ö±äÁ¿µÄ¿ªÍ·±ØÐëÊÇÒ»¸ö×Öĸ»òÏ»®Ïß“_”¡£
  • A variable name can only contain alpha-numeric characters and underscores (a-Z, 0-9, and _ )
    Ò»¸ö±äÁ¿µÄÃû³ÆÖ»Äܰüº¬×Öĸ¡¢Êý×Ö¡¢Ï»®Ïß“_”£¨¼´£ºa-Z, 0-9 ºÍ _£©
  • A variable name should not contain spaces. If a variable name should be more than one word, it should be separated with underscore ($my_string), or with capitalization ($myString)
    ±äÁ¿Ãû³Æ²»Äܺ¬Óпոñ£¨space£©¡£Èç¹ûÒ»¸ö±äÁ¿ÖÐÐèÒª°üº¬¶à¸öµ¥´Ê£¬Äǵ¥´ÊÖ®¼ä±ØÐëÒÔÏ»®Ïß“_”Á¬½Ó£¬È磺($my_string)£»»òÕßʹÓôóд×Öĸ£¬È磺($myString)

ÆÀÂÛ (1) 1 All