데이터 베이스/웹 DB

웹 DB 실습 1

Gh1324 2019. 3. 13. 10:49
728x90

<?

$a = 1; /* not global scope */

$b = 2;

Function Sum(){

global $a, $b;

$b = $a + $b;

/* reference to local scope variable */

}

Sum();

echo $b;

?>

<hr>

<Html>


<head>

<title>배열 테스트-1</title>

</head>

<body>

<?

$name[]= "김기영";

$name[]= "김상주";

$name[]= "이상무";

$name[]= "박기찬";

$number=count($name);

print("멤버는 모두 ".$number."명 입니다<br>\n");


for($i=0;$i<$number;$i++){

print("$name[$i]");

}

print("<br>내맘에 드는 멤버는 $name[2]임<br>\n");

?>


</body>


</html>

<hr>


<html>

<head>

<title>배열 테스트-2</title>

</head>

<body>


<?

$요일 = array(

1=>"월요일", "화요일", "수요일", "목요일", "금요일", "토요일", "일요일",

"월"=>"Mon", "화"=>"Tus", "수"=>"Wed", "목"=>"Thu","금"=>"Fri","토"=>"Sat", "일"=>"Sun");

print("내 생일은 이번주 $요일[5] 이다 <br>\n");

print("내 가방 상표는 black ". $요일["금"]."이다<br>\n");

?>



</body>


</html>


<hr>


<html>

<head>

<title> 배열테스트-3</title>

</head>

<body>


<?

$점수 = array(1=>array(10, 20, 30), array(30, 40, 50), array(100, 80, 90));

print("1반 최고 성적은 ".$점수[1][2]."이다.<br>\n");

print("2반 최고 성적은 ".$점수[2][2]."이다.<br>\n");

print("3반 최고 성적은 ".$점수[3][0]."이다.<br>\n");


$거래처 = array(

"서울" => array("롯데", "신세계", "미도파"),

"강릉" => array("대한통운", "One마트"),

"광주" => array("광주", "전라")

);

print("서울 거래처는 ");

for($i=0;$i<count($거래처["서울"]);$i++)

print($거래처["서울"][$i]." ");

print("<br>");


print("강릉 거래처는 ");

for($i=0;$i<count($거래처["강릉"]);$i++)

print($거래처["강릉"][$i]." ");

print("<br>");


print("광주 거래처는 ");

for($i=0;$i<count($거래처["광주"]);$i++)

print($거래처["광주"][$i]." ");

print("<br>");

?>


</body>





</html>


<hr>


<?php

$animals = array("lion","elephant","tiger");

list($key, $value) = each($animals);

print("$key : $value<br>\n");

list($key, $value) = each($animals);

print("$key : $value<br>\n");

list($key, $value) = each($animals);

print("$key : $value<br>\n");



?>


<hr>


<?php

$animals = array("lion", "elephant","tiger");

function printElement1($element){

print("printElement1 : $element<br>\n");

}

function printElement2($element){

print("printElement2 : $element<br>\n");

}

function changeElement($element){

$element = "snake";

}


array_walk($animals, "printElement1");

array_walk($animals, "printElement2");

array_walk($animals, "changeElement");


print("changeElement함수 호출후 animals[0] : $animals[0]<br>\n");

?>


<hr>


<?php

$animals = array("lion", "elephant","tiger");

for($index =0;$index<count($animals); $index++){

print("current :". current($animals)."<br>\n");

$temp = each($animals);

print("each : ". $temp[0]."".$temp[1]."<br>\n");

print("each : ". $temp["key"]."".$temp["value"]."<br>\n");

}


?>


<hr>

<?php

$animals = array("lion","elephant","tiger");

$zoo = current($animals);

do{

print("$zoo <br>\n");

} while($zoo = next($animals))

?>


728x90

'데이터 베이스 > 웹 DB' 카테고리의 다른 글

mysql 실습  (0) 2019.03.25
1부터 50까지 더하는 php 프로그램 작성하기  (0) 2019.03.20
웹 DB 실습 4  (0) 2019.03.20
웹 DB 실습 3  (0) 2019.03.18
웹 DB 실습 2  (0) 2019.03.13