if 문
1
2
3
4
5
6
7
8
<?PHP
    if($a == 'c')
        print "Continued...<br>";
    else if($a == 's')
        print "Selected...<br>";
    else
        print "Mistyped...<br>";
?>
cs


switch 문

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
    $a = 'c';
    switch($a)
    {
        case 'c':
            print "Continued...<br>";
        break;
        case 's':
            print "Selected...<br>";
        break;
        default:
            print "Mistyped...<br>";
        break;
    }
?>


'프로그래밍 > PHP' 카테고리의 다른 글

(PHP) 일반변수와 세션변수 차이  (0) 2016.07.10
(PHP) URL 파싱하기  (0) 2016.07.10
(PHP) Sort 함수를 이용하여 내림차순 정렬 만들기  (0) 2016.07.10
(PHP) for문과 배열  (0) 2016.07.10
(PHP) 배열과 정렬  (0) 2016.07.10

배열을 내림차순으로 정렬하고 싶다. sort() 함수를 이용하여 revsort() 함수를 설계하시오.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
    function revsort(&$temp)
    {
        $result = $temp;
        sort($result);
        $cnt=0;
        for($i=count($result)-1;$i>=0;$i--){
            $temp[$cnt++]=$result[$i];
        }
    }
    $Number1=array(2,17,23,5,9,15,1,3,7,22);
    revsort($Number1);
    
    foreach($Number1 as $obj)
    {
        print $obj." ";
    }
?>
cs

 


출력결과


'프로그래밍 > PHP' 카테고리의 다른 글

(PHP) URL 파싱하기  (0) 2016.07.10
(PHP) if ~ else if ~ else<-> switch~case  (0) 2016.07.10
(PHP) for문과 배열  (0) 2016.07.10
(PHP) 배열과 정렬  (0) 2016.07.10
(PHP) 파일 사용하기  (0) 2016.07.10

for문을 이용하여 다음과 같은 출력을 하는 프로그램을 작성하시오


A

AB

ABC

ABCD

ABCDE

ABCD

ABC

AB

A


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
    $temp = array("A","B","C","D","E");
    for($i=0;$i<5;$i++)
    {
        for($j=0;$j<=$i;$j++)
        {
            print $temp[$j];
        }
        print "<br>";
    }
    for($i=3;$i>=0;$i--)
    {
        for($j=0;$j<=$i;$j++)
        {
            print $temp[$j];
        }
        print "<br>";
    }
?>
cs

 


출력결과


+ Recent posts