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

[±Ð¾Ç] (PHP+IIS+MsSQL±Ð¾Ç²Ä11½g) ¦hºû°}¦C

[±Ð¾Ç] (PHP+IIS+MsSQL±Ð¾Ç²Ä11½g) ¦hºû°}¦C

¦hºû°}¦C
¦hºû°}¦C¡]Multi-dimensional¡^¡A°}¦C¤¤ÁÙ¦³°}¦C´NºÙ¤§¦hºû°}¦C¡A§Ú­Ì¤§«e©Ò»¡©úªº¬O¤@ºû°}¦C¡A¦]¬°§Ú­Ì¥u«ü©w¤F¤@­Ó°}¦C­Ó¼Æ¯Á¤Þ¡A¦pªG§Ú­Ì«ü©w¤F¨â­Ó°}¦C­Ó¼Æ¯Á¤Þ¡A¨º³o­Ó°}¦C´N¦¨¬°¤Gºû°}¦C¡A­Y¦pªG§Ú­Ì«ü©w¤F¤T­Ó°}¦C­Ó¼Æ¯Á¤Þ¡A¨º³o­Ó°}¦C´N¦¨¬°¤Tºû°}¦C¡A¥H¦¹Ãþ±À¡C

¤Gºû°}¦Cªº«Å§i
¤@ºû°}¦C¬O¥u¦³¤@¦æªº¸ê®Æ±Æ¦C¡A¦Ó¤Gºû°}¦Cªº¸ê®Æ±Æ¦C´N¦p¦Pªí®æ¤@¯ë¡A¤À¬°¡u¦æ¡v»P¡u¦C¡v¡G


©Ò¥H¡A§Ú­Ì­n¨Ï¥Î¤Gºû°}¦C®É¡A´N­n¦p¤U¦C¤è¦¡¨Óªì©l¡G
¼Ð·Ç°}¦Cªì©l®æ¦¡
  1. $°}¦C¦WºÙ[X][Y]=ªì©l­È;
½Æ»s¥N½X
¤W¦¡¤¤¡G¡uX¡v¬°¡u¦C¡vªº¤j¤p¡F¡uY¡v¬°¡u¦æ¡vªº¤j¤p¡C
¨Ò¦p¡G ªì©l¤@­Ó3x2ªº¤Gºû°}¦C
  1. $Myarray[0][0]="¤p»x";
  2. $Myarray[0][1]="egge";
  3. $Myarray[1][0]="chiey";
  4. $Myarray[1][1]="connie";
  5. $Myarray[2][0]="¤p³½";
  6. $Myarray[2][1]="¤p©M";
½Æ»s¥N½X
ª`·N³á¡I«Å§i¤@­Ó3x2ªº¤Gºû°}¦C¡A¨ä¦Cªº³Ì¤jµù¼ÐÀ³¸Ó¬°2¦æªº³Ì¤jµù¼ÐÀ³¸Ó¬O1¤~¹ï³á¡I¨ä¤¤¦C¤¸¯À¬O0~2¦@¤T­Ó¡A¦æ¤¸¯À«h¬O0~1¦@¨â­Ó¡G
2.png


°²³]§Ú­Ì¦³¤@­Ó¾Ç¥Í¦¨¿nªí®æ¦p¤U¹Ï¡A½Ð¥H¤Gºû°}¦C¤è¦¡Àx¦sªí®æ¤º¸ê®Æ¡G


­n±Nªí®æ¸ê®ÆÂà´«¦¨°}¦C§Î¦¡¡A§Ú­Ì¥i¥H³o¼Ë°µ¡G
  1. $Student[0][0]=¡¨©m¦W¡¨; //¡¥±N²Ä¤@¦C²Ä¤@¦æªº¸ê®Æ«ü©w¬°¡¨©m¦W¡¨
  2. $Student[0][1]=¡¨°ê¤å¡¨; //±N²Ä¤@¦C²Ä¤G¦æªº¸ê®Æ«ü©w¬°¡¨°ê¤å¡¨
  3. ¥H¤U²¤¡K
½Æ»s¥N½X
´N¬O¥H³v­Ó¤¸¯À¸ê®Æ¶ñ¤Jªº¤è¦¡¡A¯÷±N¤¸¯Àµù¼Ð¹ï·Ó¦p¤U¹Ï;



array()¨ç¼Æ¥ç¥iÀ³¥Î©ó¤Gºû°}¦Cªºªì©l¡A°µªk¬O¡G±N¡u¦C¡vµø¬°¤@ºû°}¦C¡A¦Ó¦¹¤@¡u¦C¡v°}¦Cªº¤¸¯À«h¬°¡u¦æ¡v°}¦C¡A¥H¾Ç¥Í¦¨ÁZªí¨Ó»¡¡G
  1. $Student=array(
  2. "0"=>array(0=>"©m¦W",1=>"°ê¤å",2=>"­^¤å",3=>"¼Æ¾Ç"),
  3. "1"=>array(0=>"¤p»x",1=>100,2=>90,3=>80),
  4. "2"=>array(0=>"±oµØ",1=>60,2=>100,3=>70),
  5. "3"=>array(0=>"«F«Ê",1=>90,2=>80,3=>90),
  6. "4"=>array(0=>"¾Ç¦³",1=>65,2=>90,3=>80));
½Æ»s¥N½X
·íµM¡A¹ï©ó«D³sÄòµù¼Ðªº¤Gºû°}¦C©Î¬O¦r¦êµù¼Ð°}¦C¡A¨Ï¥Îarray()¨ç¼Æ¤]¬O¦æªº³qªº¡A¨Ò¦p¡G
  1. <?
  2. $Student=array(
  3. "¤p»x"=>array("a"=>100,2=>90,"b"=>80),
  4. "±oµØ"=>array(1=>60,"c"=>100,3=>70),
  5. "«F«Ê"=>array("d"=>90,2=>80,"e"=>90));
  6. ?>
½Æ»s¥N½X
¤W¨Òµ¥¦P¡G
  1. $Student["¤p»x"]["a"]=100;
  2. $Student["¤p»x"][2]=90;
  3. $Student["¤p»x"]["b"]=80;

  4. $Student["±oµØ"][1]=60;
  5. $Student["±oµØ"]["c"]=100;
  6. $Student["±oµØ"][3]=70;

  7. $Student["«F«Ê"]["d"]=90;
  8. $Student["«F«Ê"][2]=80;
  9. $Student["«F«Ê"]["e"]=90;
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

¤Gºû°}¦Cªº¦s¨ú
­n¦s¨ú¤Gºû°}¦C¤¸¯Àªº¸ê®Æ«Ü²³æ¡A´N¦p¦P³B²z¤@ºû°}¦C¡A¤£¹L¡A§Ú­Ì¥²¶·¦P®É«ü©w¤¸¯Àªº¦Cµù¼Ð»P¦æµù¼Ð¡A¨Ò¦p¡G
  1. $Myarray [0][1] = 999;  //±N¸ê®Æ¦s©ñ¸m°}¦C¦ì¸m[0][1]¤¤
  2. $Myarray[1][2] = 888;  //±N¸ê®Æ¦s©ñ¸m°}¦C¦ì¸m[1][2]¤¤
  3. //¨ú¥X°}¦C¦ì¸m[0][1]»P[1][2]ªº¸ê®Æ¬Û´î¡A¨Ã¦s¦Ü°}¦C¦ì¸m[3][3]¤¤
  4. $Myarray[3][3]= $Myarray[0][1]- $Myarray[1][2];
½Æ»s¥N½X
¦pªG­n¥H°j°é±Ô­z¨Ó¦s¨ú¤Gºû°}¦Cªº¸ê®Æ¡A«h¥²¶·¨Ï¥Î±_ª¬ªº°j°é¡A§Ú­Ì¥Hfor±_ª¬°j°é¿é¥X¤Gºû°}¦C¤ºªº¸ê®Æ¨Ó»¡©ú¡G
  1. <HTML>
  2. <HEAD>
  3. <TITLE>ex04_13</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <?
  7. $Student=array(
  8. "0"=>array(0=>"©m¦W",1=>"°ê¤å",2=>"­^¤å",3=>"¼Æ¾Ç"),
  9. "1"=>array(0=>"¤p»x",1=>100,2=>90,3=>80),
  10. "2"=>array(0=>"±oµØ",1=>60,2=>100,3=>70),
  11. "3"=>array(0=>"«F«Ê",1=>90,2=>80,3=>90),
  12. "4"=>array(0=>"¾Ç¦³",1=>65,2=>90,3=>80));
  13. ?>
  14. <table border=1>
  15. <?
  16. $i=count($Student);
  17. for($x=0;$x<$i;$x++)
  18. {
  19.   echo "<tr>";
  20.   $j=count($Student[$x]);
  21.   for ($y=0;$y<$j;$y++)
  22.    {
  23.    echo ("<td>" . $Student[$x][$y] . "</td>");
  24.    }
  25.   echo "</tr>";
  26. }
  27. ?>
  28. </table>
  29. </BODY></HTML>
½Æ»s¥N½X
¹ï©ó³sÄòµù¼Ðªº¤Gºû°}¦C¨Ï¥Î±_ª¬for°j°é¥i¥H»´©öªº¸Ñ¨M¡A¦ý¬O­Y¹ï©ó«D³sÄòµù¼Ð©Î¦r¦êµù¼Ðªº°}¦C´N¦æ¤£³q¤F¡A¦¹®É­n§ï¥Î±_ª¬ªºforeach°j°é¤~¯à¸Ñ¨M¡A¨Ò¦p¡G
  1. <HTML>
  2. <HEAD>
  3. <TITLE>ex04_14</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <table border=1>
  7. <?
  8. $Student=array(
  9. "¤p»x"=>array("a"=>100,2=>90,"b"=>80),
  10. "±oµØ"=>array(1=>60,"c"=>100,3=>70),
  11. "«F«Ê"=>array("d"=>90,2=>80,"e"=>90));

  12. foreach ($Student as $key=>$value)
  13. {
  14. echo "<tr>";
  15. foreach ($value as $key1=>$value1)
  16. {
  17. echo "<td>¤¸¯Àµù¼Ð: $key,$key1 ; ¤¸¯À­È: $value1 </td>";
  18. }
  19. echo "</tr>";
  20. }
  21. ?>
  22. </table>
  23. </BODY></HTML>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

°}¦C±Æ§Ç
­n¹ï°}¦C¤¸¯Àªº¸ê®Æ¥[¥H¶¶§Ç±Æ¦C¡A¤£»Ý­n§Ú­Ì¦Û¤vÂà¼gµ{¦¡±Ô­z¡Aª½±µ¨Ï¥ÎPHP©Ò´£¨Ñªº¨ç¼Æ§Y¥i¡G


sort()¨ç¼Æ
sort()¨ç¼Æ¥i®Ú¾Ú¦r¥À¶¶§Ç©Î¼Æ­È¤j¤p¥[¥H±Æ§Ç¡G
  1. <?
  2. $X[0] ="tw";
  3. $X[1] ="com";
  4. $X[2] ="net";
  5. $X[3] ="gov";

  6. sort($X);
  7. foreach ($X as $key=>$value)
  8. {
  9. echo "¤¸¯À $key;¤¸¯À­È $value <br>";
  10. }
  11. ?>
½Æ»s¥N½X
·í¤W¨Ò°õ¦æ«áºô­¶¥X²{¦p¤U¡G



asort()¨ç¼Æ
sort()¨ç¼Æ¹ï°}¦C¤¸¯À±Æ§Ç«á¡A«h°}¦C¤¤ªº¤¸¯Àµù¼Ð¯Á¤Þ±N·|³Q­«·s½s±Æ¡A¦p¤U¨Ò¡G
  1. <?
  2. $X[252] ="com";
  3. $X[20] ="gov";
  4. $X[100] ="net";
  5. $X[] ="tw";

  6. sort($X);
  7. foreach ($X as $key=>$value)
  8. {
  9. echo "¤¸¯À $key;¤¸¯À­È $value <br>";
  10. }
  11. ?>
½Æ»s¥N½X
·í¤W¨Ò°}¦C³Qsort()¨ç¼Æ±Æ§Ç¤¸¯À«á¡A°}¦C¤¸¼Æªºµù¼Ð»P¤¸¯À­ÈªºÃö«Y¦p¤U¹Ï©Ò¥Ü¡G


­Õ­Y¡A­n°}¦C¶i¦æ¤¸¯À±Æ§Ç¡A¤S­n«O¯d¤¸¯À­ì¦³ªºµù¼Ð¯Á¤Þ¡A«h¥²¶·¨Ï¥Îasort()¨ç¼Æ¶i¦æ±Æ§Ç¡G
  1. <?
  2. $X=array("charles" => "¤p»x",
  3.          "connie" => "µL§Àºµ",
  4.          "chiey" => "¤pÃQ",
  5.          "egge" => "¤p³½");

  6. asort($X);
  7. foreach ($X as $key=>$value)
  8. {
  9. echo "¤¸¯À $key;¤¸¯À­È $value <br>";
  10. }
  11. ?>
½Æ»s¥N½X
¤W¨Òµ²ªG¦p¤U¹Ï¡A¤¸¯À¤w¸g¥[¥H±Æ§Ç¡A¦ý¤]«O¯d¤F¤¸¯À­ì¨Óªºµù¼Ð¯Á¤Þ­È¡G



rsort()¨ç¼Æ»Parsort()¨ç¼Æ
sort()¨ç¼Æ¬O¹ï°}¦C¤¸¯À¥¿¦V±Æ§Ç¡A¦Órsort()¨ç¼Æ«h¹ï°}¦C¤¸¯À¶i¦æ°f¦V±Æ§Ç¡A²{¦b¥H¬Û¦Pªº°}¦C¨Ï¥Îrsort()±Æ§Ç¡G
  1. <?
  2. $X[252] ="com";
  3. $X[20] ="gov";
  4. $X[100] ="net";
  5. $X[] ="tw";

  6. rsort($X);
  7. foreach ($X as $key=>$value)
  8. {
  9. echo "¤¸¯À $key;¤¸¯À­È $value <br>";
  10. }
  11. ?>
½Æ»s¥N½X
¥Ñ¤W¨Ò¤¤±z·|µo²{¡Arsort()¨ç¼Æ·|¹ï°}¦C¤¸¯À°f¦V±Æ§Ç¡A¦P®É¤]±N¤¸¯Àªº­ì©lµù¼Ð¯Á¤Þ­«·s½s±Æ¤F¡I


­Y­n¹ï°}¦C¤¸¯À°f¦V±Æ§Ç¡A¦ý¤£­«·s½s±Æ¤¸¯Àªº­ì©lµù¼Ð¯Á¤Þ¡A«h¥²¶·¨Ï¥Îarsort()¨ç¼Æ¨Ó±Æ§Ç¡G
  1. <?
  2. $X[252] ="com";
  3. $X[20] ="gov";
  4. $X[100] ="net";
  5. $X[] ="tw";

  6. arsort($X);
  7. foreach ($X as $key=>$value)
  8. {
  9. echo "¤¸¯À $key;¤¸¯À­È $value <br>";
  10. }
  11. ?>
½Æ»s¥N½X


ksort()¨ç¼Æ
¤§«e¤¶²Ðªºsort()¡Basort()¡Brsort()¡Barsort()¨ç¼Æ¡A¤£ºÞ¬O¥¿¦V©Î°f¦V³£¬O¹ï°}¦C¤¸¯À±Æ§Ç¡A¦Óksort()¨ç¼Æ«h¹ï°}¦C¡uµù¼Ð¡v±Æ§Ç¡A²{¦b¥H¬Û¦Pªº°}¦C¨Ï¥Îksort()±Æ§Ç¡G
  1. <?
  2. $X=array("charles" => "¤p»x",
  3.          "connie" => "µL§Àºµ",
  4.          "chiey" => "¤pÃQ",
  5.          "egge" => "¤p³½");

  6. ksort($X);
  7. foreach ($X as $key=>$value)
  8. {
  9. echo "¤¸¯À $key;¤¸¯À­È $value <br>";
  10. }
  11. ?>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

        ÀR«ä¦Û¦b : ºÉ¦h¤Ö¥»¥÷¡A´N±o¦h¤Ö¥»¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD