|
![](icon/private_name/1.gif) |
8³â Àü |
¹è¿À̶õ ÇϳªÀÇ º¯¼ö¿¡ ¿©·¯ °ªÀ» ÀúÀåÇÒ ¼ö Àִ Ư¼öÇÑ º¯¼ö¸¦ ¸»ÇÕ´Ï´Ù. ¿¹¸¦ µé¾î ´ÙÀ½ÀÇ º¯¼ö°¡ ÀÖ´Ù°í °¡Á¤ÇØ º¸°Ú½À´Ï´Ù.
ex #1)
<?php
$cars1 = "Volvo";
$cars2 = "BMW";
$cars3 = "Toyota";
?>
¸î °³ÀÇ º¯¼ö·Î ÀÌ·ç¾îÁø °ÍÀ̶ó¸é ¹®Á¦°¡ µÇÁö ¾Ê°ÚÁö¸¸, ºñ½ÁÇÑ À̸§À» °¡Áø º¯¼ö°¡ ¼ö ¹é °³°¡ Á¸ÀçÇÑ´Ù¸é ºñ½ÁÇÑ À̸§À» °¡Áø º¯¼ö ¶§¹®¿¡ °ü¸®°¡ ¾î·Á¿ö Áú ¼ö ÀÖÀ» °ÍÀÔ´Ï´Ù. ±×·¡¼ ´ÙÀ½°ú °°ÀÌ ÇϳªÀÇ º¯¼ö¿¡ ¿©·¯ °ªÀ» ÀúÀåÇؼ °ü¸®ÇÏ¸é ¼ö¿ùÇØ Áö°ÚÁö¿ä.
ex #2)
<?php
$cars = array("Volvo", "BMW", "Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>
¹è¿¿¡´Â À妽º ¹è¿, ¿¬°ü ¹è¿, ´ÙÂ÷¿ø ¹è¿ÀÌ Á¸ÀçÇϸç À妽º ¹è¿Àº Ç×»ó 0 ºÎÅÍ ½ÃÀÛÇؼ ÀÚµ¿À¸·Î Áõ°¡ °ªÀ» °¡Áö°Ô µË´Ï´Ù.
ex #3)
<?php
$cars = array("Volvo", "BMW", "Toyota");
// ¼öµ¿À¸·Î ¼³Á¤ ÇÑ´Ù¸é
$cars[0] = "Volvo";
$cars[1] = "BMW";
$cars[2] = "Toyota";
?>
for¹®À» ÀÌ¿ëÇÏ¿© À妽º¸¦ »ý¼ºÇÒ ¼ö ÀÖ½À´Ï´Ù.
ex #4)
<?php
$cars = array("Volvo", "BMW", "Toyota");
$length = count($cars);
for($i=0;$i<$length;$i++){
echo $cars[$i] . ¡°, ¡±;
}
// Ãâ·Â: Volvo, BMW, Toyota
?>
¿¬°ü ¹è¿À̶õ º¯¼öÀÇ À̸§À» °¡Áö´Â Å°¸¦ »ç¿ëÇÑ ¹è¿À» ¸»ÇÕ´Ï´Ù.
ex #5)
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
// ¼öµ¿À¸·Î ¼³Á¤ ÇÑ´Ù¸é
$age['Peter'] = "35";
$age['Ben'] = "37";
$age['Joe'] = "43";
echo "Peter is " . $age['Peter'] . " years old.";
?>
Foreach ¹®À» ÀÌ¿ëÇÑ ¿¬°ü¹è¿À» »ý¼ºÇÒ ¼öµµ ÀÖ½À´Ï´Ù.
ex #6)
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
foreach($age as $key=>$value){
echo "Key=" . $key . ", Value=" . $value;
echo "<br>";
}
/*
Ãâ·Â:
Key=Peter, Value=35
Key=Ben, Value=37
Key=Joe, Value=43
*/
?>
´ÙÂ÷¿ø ¹è¿Àº 1Â÷¿ø ¹è¿À» °¡Áö´Â ±âÁ¸ ¹æ½Äº¸´Ù´Â Çϳª ÀÌ»óÀÇ ¹è¿À» Æ÷ÇÔÇÏ´Â ¹è¿·Î¼ À妽º ¹è¿À̳ª ¿¬°ü ¹è¿À» º¹ÇÕÀûÀ¸·Î °¡Áú ¼ö ÀÖ½À´Ï´Ù.
ex #7)
<?php
// 2Â÷¿ø ¹è¿
$cars = array (
array("Volvo", 100, 96),
array("BMW", 60, 59),
array("Toyota", 110, 100)
);
?>
ex #8)
<?php
$families = array (
"Griffin"=>array (
"Peter",
"Lois",
"Megan"
),
"Quagmire"=>array (
"Glenn"
),
"Brown"=>array (
"Cleveland",
"Loretta",
"Junior"
)
);
/*
Ãâ·Â:
Array (
[Griffin] => Array (
[0] => Peter
[1] => Lois
[2] => Megan
)
[Quagmire] => Array (
[0] => Glenn
)
[Brown] => Array (
[0] => Cleveland
[1] => Loretta
[2] => Junior
)
)
*/
echo $families['Griffin'][2];
// Ãâ·Â: Megan
?>
ex #9)
<?php
echo "Is " . $families['Griffin'][2] . " a part of the Griffin family?";
// Ãâ·Â: Is Megan a part of the Griffin family?
?> |
|
̵̧ : 379 |
̵̧
¸ñ·Ï
|
|