w3pop.com :: ÍøÂçѧԺ :: PHP :: PHP ±äÁ¿
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£©£»Ëü¿ÉÒÔÔڽű¾ÖÖÖØ¸´Ê¹Óá£
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> <?php </body> |
To concatenate two or more variables together, use the dot (.) operator:
Èç¹ûÄãÏë°ÑÁ½¸ö±äÁ¿ºÏ¶þΪһ£¬ÄãÐèҪʹÓã¨.£©²Ù×÷·û£¬¾ßÌåÈçÏ£º
<html> <?php </body> |
The output of the script above will be: "Hello World 1234".
ÉÏÊöÀý×ÓÊä³öµÄ½á¹ûÊÇ£º"Hello World 1234"