ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

2-3-2 Åܼƪº«Å§i

2-3-2 Åܼƪº«Å§i

2-3-2   Åܼƪº«Å§i
¦b¶i¦æÅܼƪº«Å§i¤§«e§Ú­Ì¥ý¨Ó¤F¸Ñ¤@¤UÅܼƪººØÃþ¡A¨Ì¾ÚÅܼƪº¼vÅT¥i·§¤À¬°¨âºØ¶Õ¤O½d³ò¡G¥þ°ìÅܼơ]Global¡^¡A¼vÅT½d³ò¹M§G¾ã­Óµ{¦¡¡A¥]¬A¨ç¼Æ¡]Function¡^¡B°Æµ{¦¡¡]Sub¡^µ¥¥þ¥]¤F¡F°Ï°ìÅܼơ]Local¡^¡A¶Õ¤O½d³ò¸û¤p¡A¥u­­©ó«Å§i¸ÓÅܼƪº°Æµ{¦¡¡]Sub¡^©Î¨ç¼Æ¡]Function¡^¤¤¡A·í°õ¦æµ{§ÇÂ÷¶}«á¡A°Ï°ìÅܼƫK¥¢¥h®Ä¤O¦Ó®ø¥¢¤F¡C²³æªº»¡¡A¥u­n¤£¬O¦b¨ç¼Æ¡]Function¡^©Î°Æµ{¦¡¡]Sub¡^¤¤«Å§iªºÅܼƴN¬O¥þ°ìÅܼưաI

¨ì©³­n¦p¦ó¥¿½Tªº«Å§iÅܼƩO¡H¦b«Å§iÅܼƤ§«e§Ú­Ì¥²¶·¥[¤@­Ó¡y¢C¡z¦r¤¸²Å¸¹¡A¤]´N¬O»¡Åܼƪº«Å§i¬O±q¡y¢C¡z¦r¤¸²Å¸¹¶}©l¡G
  1. ¢CÅܼƦWºÙ=ªì©l­È;
½Æ»s¥N½X
¨Ò¦p¡G
  1. ¢CintNumber=5;
  2. ¢CStrName=¡¨ºû¥§¡¨;
½Æ»s¥N½X
¨º¦b«Å§iÅܼƮɡA§Ú¥i¤£¥i¥H¤£«ü©wÅܼƪºªì©l­È£«¡Aµª®×¬O¤£¦æ¡A³o¼Ë·|²£¥Í¡uUndefined variable¡vªº¿ù»~´£¥Ü¡G
  1. <?
  2. $intNumber=5;
  3. $strName;
  4. echo $intNumber;
  5. ?>
½Æ»s¥N½X

¹Ï2-11   ½d¨Òch02_04.php¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

Åܼƪº¸ê®Æ«¬ºAÂà´«
ÁöµM¦b«Å§iÅܼƮɡA¤£»Ý­n©w¸qÅܼƪº¸ê®Æ«¬ºA¡A¦]¬°®Ú¾Ú¤£¦PªºÅܼƨϥήɾ÷¡A PHP·|¦Û°ÊªºÃѧOÅܼƤºªº¸ê®Æ¬OÄÝ©ó¦óºØ¸ê®Æ«¬ºA¡I¦ý§Ú­Ì¥ç¥i±j­¢¶i¦æÅܼƪº«¬ºAÂà´«¡A¨Ò¦p¡G¡]½d¨Òch02_05b.php¡^
  1. <?
  2. $a = 10;    // ¦¹®ÉÅܼƬ°integer
  3.   echo gettype($a); //¿é¥X¸ê®Æ«¬ºAinteger

  4. echo "<br>";

  5. $a = (string)$a;  //±NÅܼƪº¸ê®Æ§ÎºAÂà´«¬°string
  6.     echo gettype($a); //¿é¥X¸ê®Æ«¬ºAstring
  7. ?>
½Æ»s¥N½X
¡@·í¦r¦ê³QÂà´«¦¨­È¼Æ­È¸ê®Æ®É¡A¥H¦r¦êªº¶}ÀY¦r¤¸¯à§_¿ëÃѬ°°ò·Ç¡AµLªk¿ëÃѪº§¡Âର¼Æ­È 0¡C¡]½d¨Òch02_05c.php¡^
  1. ¡@<?
  2. $a = "1abc";    // ¦¹®ÉÅܼƬ°¦r¦ê
  3.   echo gettype($a); //¿é¥X¸ê®Æ«¬ºAstring

  4. echo "<br>";

  5. $a = (int)$a;  //±NÅܼƪº¸ê®Æ§ÎºAÂà´«¬°¾ã¼Æ
  6.     echo gettype($a); //¿é¥X¸ê®Æ«¬ºAinteger

  7. echo "<br>";

  8. $a = "e2";    // ¦¹®ÉÅܼƬ°¦r¦ê
  9. $a = (int)$a;  //±NÅܼƪº¸ê®Æ§ÎºAÂà´«¬°¾ã¼Æ
  10.   echo ($a); //¿é¥X¸ê®Æ­È¬°0
  11. ?>
½Æ»s¥N½X
¥t¥~¡A§Q¥Îsettype()¨ç¼Æ¥ç¥i§ïÅÜÅܼƪº¸ê®Æ«¬ºA¡G
  1. settype(ÅÜ¼Æ , ¸ê®Æ«¬ºA¡^
½Æ»s¥N½X
¨Ò¦p¡G¡]½d¨Òch02_05d.php¡^
  1. <?
  2. $a = "3abc";    // ¦¹®ÉÅܼƬ°¦r¦ê
  3. $b = 5;
  4. settype($a,"integer"); //±NÅܼƪº¸ê®Æ§ÎºAÂà´«¬°¾ã¼Æ
  5. echo ($a*$b); //¿é¥X¸ê®Æ­È¬°15
  6. ?>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

¬d¸ßÅܼƪº¸ê®Æ«¬ºA
­Y·Q±oª¾Åܼƪº¸ê®Æ«¬ºA¡A¥i§Q¥Îgettype()¨ç¼Æ¡A¦¹¨ç¼Æ¥i¨ú¦^integer¡Bduble¡Bstring¡Barray¡Bobject¡Bclass¡Bunknown typeµ¥«¬ºA¡G¡]½d¨Òch02_05a.php¡^
  1. <?
  2. $x="§Ú°Q¹½PHP";
  3. echo gettype($x);  //¿é¥Xstring
  4. echo "<br>";

  5. $x=123;
  6. echo gettype($x);  //¿é¥Xinteger
  7. echo "<br>";

  8. $x=123.321;
  9. echo gettype($x);  //¿é¥Xdouble
  10. echo "<br>";
  11. ?>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

ÅܼƷ|¦]µ{¦¡ªº°õ¦æ¦ÓÅÜ°Ê©Ò¦s©ñªº¸ê®Æ¤º®e¡I
¨Ò¦p¡G§Ú­Ì¨Ï¥Î¤@­ÓÅܼơux¡v¡A¦P®É±NÅܼÆxªº­È(¤]´N¬OÅܼƤº©ÒÀx©ñªº¸ê®Æ¤º®e)«ü©w¬°¡u§Ú°Q¹½PHP¡v¡AµM«á§âÅܼÆx¸ê®Æ¤º®e¿é¥X¨ìºô­¶¤¤¡A«hºô­¶¥X²{¤@­Ó¡u§Ú°Q¹½PHP¡v¡A±µµÛ§Ú­Ì¦A±NÅܼÆxªº­È«ü©w¬°¡u§Ú³ßÅwPHP¡v¡A§âÅܼÆx¸ê®Æ¤º®e¦A¦¸¿é¥X¨ìºô­¶¤¤¡Aºô­¶¤¤«o¥X²{¤@­Ó¡u§Ú³ßÅwPHP¡v¡A¥Ñ¦¹¥iª¾¡G¦bµ{¦¡°õ¦æªº¹Lµ{¤¤¡AÅܼƪº­È¬O¥iÅܰʪº¡I¡]½d¨Òch02_05.php¡^
  1. <?
  2. $x="§Ú°Q¹½PHP"; //«Å§iÅܼÆ
  3. echo $x;
  4. $x="§Ú³ßÅwPHP"; //­«·s©w¸qÅܼÆ
  5. ?>
  6. <p>
  7. <?
  8. echo $x;
  9. ?>
½Æ»s¥N½X

¹Ï2-12   ­«½Æ§Q¥ÎÅܼơC
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

        ÀR«ä¦Û¦b : ­n¤ñ½Ö§ó¨ü½Ö¡D¤£­n¤ñ½Ö§ó©È½Ö¡C
ªð¦^¦Cªí ¤W¤@¥DÃD