Header Ads

PHP 배열 정리

// 1. a배열
$a[0] = "a";
$a[1] = "b";
$a[2] = "c";
echo $a[0] . $a[1] . $a[2];
unset($a);

// 2. 배열의 키와 값
$a["a"] = "A";
$a["b"] = "B";
$a["c"] = "C";
echo $a["a"] . $a["b"] . $a["c"];
unset($a);

// 3. 배열의 생성
$a = array(0=>"a",1=>"b",2=>"c");
echo $a[0] . $a[1] . $a[2];
unset($a);

$a = array("a"=>"A","b"=>"B","c"=>"C",);
echo $a["a"] . $a["b"] . $a["c"];
unset($a);

$a = array("a","b","c");
echo $a[0] . $a[1] . $a[2];
unset($a);

$a = array("a","b"=>"B","c"=>3);
echo $a["a"] . $a["b"] . $a["c"];
unset($a);

$a[] = "a";
$a[] = "b";
$a[] = "c";
echo $a[0] . $a[1] . $a[2];
unset($a);

// 4. 다차원 배열
$a = array(
  array("a"=>"A","b"=>"B"),
  array("A"=>"a","B"=>"b")
);
echo  $a[0]["b"] . $a[1]["B"];
unset($a);

$a[0]["a"] = "A";
$a[0]["b"] = "B";
$a[0]["c"] = "C";
$a[1]["a"] = "a";
$a[1]["b"] = "b";
$a[1]["c"] = "c";
echo $a[0]["c"] . $a[1]["c"];
unset($a);

$a = array(
 "A"=>array("a"=>"A","b"=>"B","c"=>"C"),
 "B"=>array("a"=>"A","b"=>"B","c"=>"C"),
 "C"=>array("a"=>"A","b"=>"B","c"=>"C")
);
echo $a["A"]["a"] . $a["B"]["a"] . $a["C"]["b"];
unset($a);

No comments

Copyright 2016, minki. All rights reserved. Powered by Blogger.