Untitled Document











PHP 강좌

0
Total 6 articles, 1 pages/ current page is 1
   

 

  View Articles
Name  
   박우진 
Homepage  
   http://madpark.korea.ac.kr
Subject  
   PHP3 문법 기초
1. Variable (변수)
- 변수는 $로 시작한다.

- 변수는 별도로 선언하는 부분이 없으며 (type을 미리 지정하지 않으며) 변수 type은 변수가 사용된 context에 따라 결정된다.

- 변수의 type으로는 기본적으로 integer, double, string type이 있으며 이외에 array와 object type이 있다. 변수 type은 gettype(), is_long(), is_double(), is_string(), is_array(), is_object() 등의 함수로 알아낼 수 있다.

- type casting은 C에서와 같은 형식으로 이루어진다. (int) (integer) (real) (double) (float) (string) (array) (object) 등의 casting operator가 있다.

- string conversion : 문자열이 숫자로 변환될 때에 문자열이 '.', 'e', 'E'를 포함하고 있으면 double로 그렇지 않으면 integer로 변환이 된다.

- variable variable : 변수의 값이 변수의 이름이 되는 것을 말한다. 예를들어 $a = "hello" 일때 $$a = "world"라고 정의하면 $hello = "world"로 정의되는 것이다.

- scope : user-defined function에서는 local function scope가 적용된다. 즉 function 안에서 정의된 변수는 function안에서만 의미가 있다. 주의할 점은 외부에서 정의된 변수도 user-defined function안에서는 의미가 없다는 것이다. 외부에서 정의된 변수를 사용하려면 함수 안에서 global $externalVar; 형식으로 정의를 하고 사용하거나 $GLOBALS["externalVar"] 형식으로 직접 변수를 사용하여야 한다.

- static variable : local function scope를 가지지만 scope를 벗어나더라도 값이 유지되는 변수를 말한다.

Array

- array는 $array[] 형식으로 사용된다.

- scalar array : 첨자가 숫자로 주어지는 배열이다. 예를 들면 $array[0] = 1;

- associative array : 첨자가 숫자가 아니라 문자열로 주어지는 배열이다. 예를 들면 $array["first"] = 1;

- 그냥 $array[]에 값을 지정하면 array에 값이 하나 추가된다. $array[] = 1; $array[] = 2; 는 $array[0] = 1; $array[1] = 2;와 같은 의미를 지닌다.

- array() 함수를 통하여 array를 만들수도 있고, count() 함수로 element의 갯수를 얻을수도 있다. next(), prev() 함수나 each() 함수를 통하여 element들을 참조할 수도 있다.

External Variables (외부변수)

- HTML form (GET/POST) : form으로 전달된 값은 form에서 name field로 지정한 이름의 변수로 지정이 된다. form에서 type = "image"인 경우에는 마우스로 클릭한 위치가 name_x, name_y 형태로 추가로 전달된다.

- HTTP Cookie : browser로 cookie를 전달하려면 SetCookie(name, value, timeout) 함수를 이용한다. client로부터 전달되는 cookie는 PHP 변수로 변환이 된다.

- Environment Variable : 환경변수 또한 PHP 변수처럼 사용할 수 있다. 환경변수는 getenv()라는 함수를 이용해 얻을 수 있으며 putenv() 함수로 환경변수를 지정할 수도 있다.


2. Class
- class keyword를 사용하여 class를 정의하며 instance 생성은 new operator를 이용한다.

- class의 상속은 extends keyword를 사용한다.

- constructor 정의는 class와 같은 이름을 갖는 상수를 정의함으로써 이루어진다. constructor는 default parameter를 가질 수 있다.

예)

    class testClass {
        var $value;
        function testClass($defValue = "test") { $value = $defValue; }
        function doSet($setValue) { $value = $setvalue; }
        function doPrint() { echo $value; }
    }
    class testLineClass extends testClass {
        function doPrintLine() { echo("$valuen"); }
    }

    $test = new testClassLine;
    $test->doSet("hello");
    $test->doPrint();
    $test->doPrintLine();
3. Expression
- expression이란 값으로 환산되는 것을 말한다.

- assignment는 expression이므로 $a = $b = 5; 같은 문장을 쓸 수 있다.

- pre and post increment / decrement : $a++, ++$a, $a--, --$a

- comparison operator는 boolean 값을 갖는 expression이다.

- operator와 assignment의 결합 : $a += 3; $b = ++$a; $c = double(--$b); $d = $c += 10;

- boolean : 숫자에서 0은 false, 0이 아닌값은 true이다. 문자열에서 ""와 "0"은 false, 나머지는 true이다. array에서는 element가 하나도 없으면 false, 하나라도 있으면 true이다.


4. Statement
- if 문 :

    if (expression) {
        do anything 1;
    } elseif (expression) {
        do anything 2;
    } else
        do anything 3;

    또는

    if (expression) :
        do anything 1;
    elseif (expression) :
        do anything 2;
    else :
        do anything 3;
    endif;
- while 문 :

    while (expression)
        do anything;

    또는

    while (expression) :
        do anything;
    endwhile;
- do...while 문 :

    do {
        do anything;
    } while (expression);
- for 문 :

    for (expr1; expr2; expr3)
        do anything;
- switch 문 :

    switch (expression) {
    case ... :
        do anything;
        break;
    default :
        do anything;
    }
- loop에서 break를 이용한 제어가 가능하다.

5. Function (함수)
- 함수는 function 이라는 keyword를 가지고 정의가 되며 별도로 return type은 지정하지 않는다.

- function의 기본형은 다음과 같다.

    function funcName($arg1, $arg2, $arg3, ..., $argn) {
        do anything;
        return $retval;
    }
- return value는 list와 object를 포함하여 어떤 type이든 될 수 있다. 예를 들어 array를 return하려면 return array(0, 1, 2);

- argument는 default로 pass by value이다. pass by reference로 하려면 argument definition에서 변수명 앞에 &를 붙여주면 된다 (function funcName(&$arg1)). function이 pass by value로 정의가 되었더라도 함수를 부를때 argument에 &를 붙여서 넘기면 pass by reference가 된다 (call : doFunc(&$var)).

- default parameter : C++에서 사용하는 방식으로 default parameter를 정의할 수 있다 : function funcName($var = 1) { }


6. Operator
- operator들은 C언어에서의 operator와 비슷하며 다음과 같은 operator들이 있다.

- arithmetic operator : +, -, *, /, %
- string operator : . (concatenation)
- assignment operator : =
- bitwise operator : &, |, ~
- logical operator : and (&&), or (||), xor, !
- comparison operator : ==, !=, <, >, <=, >=


7. 그밖에
- require : #include와 똑같은 의미로 사용된다.

- include : include 문장을 만날때마다 지정한 파일을 포함한다. require는 #include 처럼 무조건 파일을 포함시키지만 include는 loop나 if 문 등에서 사용할 수 있으며 필요한 경우에만 파일을 포함하도록 할 수 있다.





    
bdaaeh ycV0Sf <a href="http://kxymgwhhrzko.com/">kxymgwhhrzko</a>, [url=http://lkztdoxmonny.com/]lkztdoxmonny[/url], [link=http://kbptefvyzvkm.com/]kbptefvyzvkm[/link], http://xkimxqlzrpfh.com/ 2010/03/19
inderalici comment6, http://savegau.com/ valtrex online, http://addiesrandomramblings.com/ no prescription phentermine, http://vvsangam.com/ prozac, http://babybellington.com/ prescription ultram, http://bigheadharleydog.com/ zolpidem online mx, http://floortechnicians.com/ cialis, http://abbotsfordtoastmasters.com/indaex.html meridia success stories, http://techknologyblog.com/ buy xenical in the uk, http://technostrata.com/ valtrex for herpes, http://lowbudgethookers.com/ lipitor, http://officialmissgaymidatlanticamerica.com/ less propecia, http://bloglaurentfabius.com/ cheapest generic adipex online, http://outerhavenzone.com/ effects inderal propranolol side, 2010/03/20
taking val comment5, http://stopcallingblog.com/ does like look zithromax, http://addiesrandomramblings.com/ wholesale phentermine, http://andalucistasniebla.com/ soma hernandez, http://arequipa35mm.com/ tramadol on line no prescription, http://abbotsfordtoastmasters.com/indaex.html side effects on meridia, http://bigheadharleydog.com/ zolpidem cr, http://techknologyblog.com/ xenical online, http://phrenologistsnotebook.com/ primetime tamiflu, http://officialmissgaymidatlanticamerica.com/ cheap propecia online, http://schemelessmoney.com/ sample viagra, http://mynameisrobot.org/ 10mg nolvadex, 2010/03/20
metformin comment6, http://oxfordhypnosis.com/ rimonabant, http://mondayleadsgroup.com/ cheap nexium, http://bdcgamer.com/ ultram, http://localadvisor.net/ levitra online, http://2ksyllo.net/ klonopin generic, http://lowbudgethookers.com/ generic name for lipitor, http://mynameisrobot.org/ order nolvadex, 2010/03/20
valium fac comment5, http://outrodesigns.com/ retin a benefits, http://bestguessphotography.com/ valium tablet, http://andreawidmer.com/ avian flu tamiflu, http://scottlukaitisphotography.com/ xenical, http://localadvisor.net/ levitra plus 30 pills, http://terriblepoetry.com/ nolvadex sale, http://suburbanfoodforthought.com/ tetracyclines, http://schemelessmoney.com/ viagra usa buy, http://stpetersanglicanchurchwisbech.com/ generic zithromax, http://bginternet-tv.info/ drug interaction xanax, 2010/03/20
buy xenica comment2, http://monasheephotography.com/ cheap nexium, http://replifyblog.com/ cheap tetracycline, http://oxfordhypnosis.com/ rimonabant, http://tfun.info/ migraine propranolol, http://lisamccannherbs.com/ levaquin online qoclick, http://stopcallingblog.com/ pak z zithromax, http://andalucistasniebla.com/ soma without a perscription, http://abbotsfordtoastmasters.com/indaex.html meridia, http://scottlukaitisphotography.com/ xenical dosage, http://bird-watching.info/ phentermine 37.5 information, http://suburbanfoodforthought.com/ tetracycline stain on tooth, http://bcnblsa.com/ tramadol bedroom online, http://mynameisrobot.org/ nolvadex, 2010/03/20
pregnancy comment1, http://savegau.com/ buy valtrex, http://bestguessphotography.com/ valium pregnancy, http://techknologyblog.com/ buy xenical, http://andreawidmer.com/ mauritius tamiflu, http://flyprint.net/ buy viagra luxembourg, http://scottlukaitisphotography.com/ buy xenical, http://terriblepoetry.com/ novo-tamoxifen, http://officialmissgaymidatlanticamerica.com/ cheap real propecia, http://bginternet-tv.info/ xanax trade names, http://localmessiah.com/ anxiety drug lexapro, 2010/03/20
propranolo comment1, http://monasheephotography.com/ nexium, http://addiesrandomramblings.com/ phentermine no prescription, http://andalucistasniebla.com/ soma, http://mayanhostel.com/ what is metformin hcl, http://139666.com/ diazepam journals, http://officialmissgaymidatlanticamerica.com/ uk propecia sales, http://atozsportslive.com/ valium and xanax, http://bginternet-tv.info/ order xanax without a prescription, http://mynameisrobot.org/ nolvadex online, http://alencon-bridal.com/ 37.5mg phentermine, 2010/03/20
benefit of comment4, http://maranathabible.net/ how does metformin work, http://outrodesigns.com/ retin a acne treatment, http://oxfordhypnosis.com/ acomplia buy rimonabant, http://mondayleadsgroup.com/ nexium, http://savegau.com/ valtrex, http://addiesrandomramblings.com/ phentermine, http://andalucistasniebla.com/ soma intimates, http://bigheadharleydog.com/ zolpidem, http://floortechnicians.com/ cialis viagra levitra, http://bdcgamer.com/ drug test ultram, http://2ksyllo.net/ klonopin, http://suburbanfoodforthought.com/ pharmacy online tetracycline, http://localmessiah.com/ lexapro, http://mynameisrobot.org/ nolvadex proviron, 2010/03/21
ultram and comment4, http://babybellington.com/ ultram pain, http://bdcgamer.com/ ultram overnight, http://technostrata.com/ valtrex online, http://officialmissgaymidatlanticamerica.com/ pill propecia, http://outerhavenzone.com/ medicine propranolol, 2010/03/21
xenical ge comment2, http://replifyblog.com/ tetracycline medication side effects, http://maranathabible.net/ appetite metformin, http://alexkenny.com/ reductil, http://stopcallingblog.com/ cause rash zithromax, http://technostrata.com/ information on valtrex dosing, http://bestguessphotography.com/ valium, http://blogunknown.com/ viagra online store, http://andreawidmer.com/ tamiflu oral suspension, http://bird-watching.info/ usa phentermine, http://suburbanfoodforthought.com/ tetracycline side effects, http://bcnblsa.com/ tramadol, http://atozsportslive.com/ valium cat remedy, http://bginternet-tv.info/ xanax overdose amount, http://frenteecologico.org/ viagra cialis levitra, 2010/03/21
effects si comment5, http://savegau.com/ valtrex patent, http://abbotsfordtoastmasters.com/indaex.html meridia capital, http://technostrata.com/ valtrex, http://bird-watching.info/ phentermine, http://lowbudgethookers.com/ lipitor medication, http://stpetersanglicanchurchwisbech.com/ pregnancy zithromax, http://atozsportslive.com/ ativan valium, http://mynameisrobot.org/ nolvadex 10mg, http://alencon-bridal.com/ online pharmacy phentermine, 2010/03/21
xanax mexi comment6, http://alexkenny.com/ cheapest reductil, http://shoesonmybike.com/ zimulti, http://addiesrandomramblings.com/ phentermine by fedex, http://andalucistasniebla.com/ soma, http://vvsangam.com/ prozac buy on, http://babybellington.com/ ultram, http://technostrata.com/ valtrex while nursing, http://terriblepoetry.com/ nolvadex 30 pills, http://139666.com/ cheap diazepam, http://atozsportslive.com/ buy valium, http://bginternet-tv.info/ xanax, http://outerhavenzone.com/ propranolol beta blocker, 2010/03/21
buy tamifl comment2, http://tfun.info/ 10 apo mg propranolol, http://savegau.com/ valtrex drug, http://mayanhostel.com/ generic metformin, http://babybellington.com/ ultram er addiction, http://bigheadharleydog.com/ zolpidem without prescription, http://floortechnicians.com/ generic cialis online, http://bdcgamer.com/ ultram antidepressant, http://techknologyblog.com/ xenical, http://andreawidmer.com/ oseltamivir tamiflu, http://2ksyllo.net/ cod klonopin, http://agricultlore.org/ cheapest reductil, http://suburbanfoodforthought.com/ tetracycline, http://officialmissgaymidatlanticamerica.com/ propecia 1mg, 2010/03/25
cialis low comment1, http://maranathabible.net/ metformin dosage, http://tfun.info/ propranolol used, http://mondayleadsgroup.com/ buy nexium online, http://vvsangam.com/ prozac withdrawal symptoms flu, http://mayanhostel.com/ metformin and breastfeeding, http://abbotsfordtoastmasters.com buy meridia, http://bestguessphotography.com/ valium and migraine headaches, http://scottlukaitisphotography.com/ xenical, http://2ksyllo.net/ klonopin 0 5mg, http://bird-watching.info/ phentermine, http://phrenologistsnotebook.com/ tamiflu side effects, http://terriblepoetry.com/ effects gh nolvadex, http://bloglaurentfabius.com/ buy phentermine adipex-p online, http://outerhavenzone.com/ propranolol, 2010/03/25
nolvadex r comment1, http://monasheephotography.com/ nexium testimony, http://australianacryliccasting.com/ xanax and mastercard, http://mondayleadsgroup.com/ nexium, http://savegau.com/ valtrex cfs, http://bdcgamer.com/ ultram, http://localadvisor.net/ levitra, http://bloglaurentfabius.com/ no perscription adipex, http://fraudfiles.org/ levitra online, 2010/03/25
remonabent comment5, http://replifyblog.com/ acne tetracycline treatment, http://alexkenny.com/ meridia reductil, http://mayanhostel.com/ generic metformin, http://abbotsfordtoastmasters.com side effects on meridia, http://technostrata.com/ real valtrex, http://agricultlore.org/ reductil tablets, http://stpetersanglicanchurchwisbech.com/ zithromax 500mg tablet, http://lowbudgethookers.com/ side effects of lipitor, http://schemelessmoney.com/ online order viagra, http://localmessiah.com/ lexapro vs paxil, http://mynameisrobot.org/ nolvadex, http://alencon-bridal.com/ phentermine, 2010/03/25
viagra and comment2, http://jojobillingsley.com/ levitra 10 mg order, http://juancarlosnavanava.com/ accutane and ibd, http://adboficial.com/ alprazolam 0.25mg, http://asherpen.info/ diazepam, http://psychicmirandatempest.com/ metformin rash, http://klearfotos.net/ antabuse online, http://10sation.com/ buy adipex online, http://creativespecial.com/ zithromax, 2010/03/31
valium comment3, http://almightypaulmighty.com/ cialis impotence drug eli lilly co, http://renegadesfastpitch.com/ anxiety propranolol, http://lecabestan.org/ cymbalta and weight, http://nataliechow.com/ buy cialis viagra, http://adboficial.com/ buy alprazolam, http://ccfirstlove.com/ tamiflu side effects, http://aaronsanko.com/ adipex, http://positivegolf.org/ actress in levitra commercial, http://ecocab-va.com/ adipex, http://klearfotos.net/ alcoholism antabuse medication, http://ididnthateit.com/ viagra 60 pills, 2010/03/31
alcohol pr comment4, http://juancarlosnavanava.com/ accutane after before picture, http://aaronsanko.com/ adipex diet drug, http://cosmeticsculptra.com/ zolpidem side affects, http://070209.com/ acomplia, http://pat4travel.com/ diuretic lasix, http://ruthlesspropaganda.com/ glucophage loss weight, 2010/03/31
cialis sal comment1, http://jihadutube.com/ by cialis comment powered uri wordpress, http://lecabestan.org/ recent news on cymbalta, http://adboficial.com/ alprazolam opioid, http://ronansays.com/ cheap retin-a, http://ecocab-va.com/ adipex, http://joearmendariz.org/ soft tab viagra, http://rarewines101.com/ prednisone withdrawal, http://gc-books.com/ phentermine without prescription, http://creativespecial.com/ zithromax info, http://fromtheunderground.com/ phentermine, http://allthatglittersevents.com/ bactrim, 2010/03/31
how to abu comment6, http://lecabestan.org/ cymbalta detoxification, http://juancarlosnavanava.com/ accutane, http://charliehallpicturearchive.com/ injecting ultram, http://ecocab-va.com/ buy adipex-p phentermine online, http://joearmendariz.org/ viagra, http://jdmprophecy.com/ levitra, 2010/04/01
cialis wes comment6, http://boss-series.com/ buy propecia from usa, http://elciclo.com/ adipex, http://juancarlosnavanava.com/ new york accutane lawyer, http://ronansays.com/ retin a acne, http://allenglishpottery.com/ ambien doseage, http://cosmeticsculptra.com/ zolpidem overseas, http://pozolefilms.com/ lipitor life insurance, http://kappakappamoose.com/ amoxil 30 pills, http://allthatglittersevents.com/ aureus bactrim staph staphylococcus, 2010/04/01
cheap phen comment1, http://renegadesfastpitch.com/ propranolol, http://asherpen.info/ diazepam overdose, http://gregsdrawings.com/ phentermine online, http://ronansays.com/ retin-a, http://blogseucarro.com/ side effects with lipitor, http://everybodyisstupidbutme.com/ adipex-p, http://creativespecial.com/ zithromax alcohol, http://jesusmuch.org/ viagra price, http://allthatglittersevents.com/ bactrim, 2010/04/01
viagra cia comment4, http://jihadutube.com/ cialis.com, http://asherpen.info/ diazepam online, http://charliehallpicturearchive.com/ half life of ultram, http://collegetunnel.info/ arsenic and xanax, http://bmegadget.com/ meridia canada pills, 2010/04/01
ultram comment3, http://jojobillingsley.com/ levitra, http://glagly.org/ phentermine, http://gregthiel.com/ atropine diazepam cana, http://lecabestan.org/ cymbalta vs zoloft, http://elciclo.com/ adipex, http://juancarlosnavanava.com/ accutane, http://blogseucarro.com/ lipitor, http://chevaughn.com/ valium percocet interaction, http://allenglishpottery.com/ ambien, http://joearmendariz.org/ viagra online, http://creativespecial.com/ zithromax online, http://peterbourkeracing.com/ levaquin and alcohol, 2010/04/01
female via comment3, http://jihadutube.com/ cialis, http://lecabestan.org/ cymbalta vs prozac, http://ronansays.com/ retin a over the counter, http://gregsdrawings.com/ cheap phentermine, http://cornwallpost353.com/ xenical tablets, http://charliehallpicturearchive.com/ half life of ultram, http://everybodyisstupidbutme.com/ adipex-p, http://creativespecial.com/ zithromax and hemroids, http://centralhotbots.org/ order tramadol overnight, http://collegetunnel.info/ the effects of xanax, http://allthatglittersevents.com/ bactrim, 2010/04/01
valium and comment1, http://rothakelly.com/ zimulti, http://psychicmirandatempest.com/ metformin, http://bloghighered.org/ cialis levitra, http://allenglishpottery.com/ buy ambien, http://joearmendariz.org/ viagra, http://pozolefilms.com/ lipitor, http://070209.com/ buy online acomplia, 2010/04/01
dosage tam comment4, http://almightypaulmighty.com/ cialis generic, http://ronansays.com/ buy generic retin, http://gregsdrawings.com/ phentermine, http://blogseucarro.com/ lipitor congestion, http://ecocab-va.com/ adipex online, http://chevaughn.com/ valium, http://cosmeticsculptra.com/ zolpidem, http://joearmendariz.org/ buy viagra now, http://070209.com/ acomplia online, http://jdmprophecy.com/ levitra, http://pat4travel.com/ 40 buy lasix mg, http://jesusmuch.org/ cheap viagra, http://peterbourkeracing.com/ levaquin, 2010/04/01
valium comment5, http://juancarlosnavanava.com/ accutane start working, http://asherpen.info/ diazepam, http://charliehallpicturearchive.com/ ultram, http://psychicmirandatempest.com/ natural alternatives to metformin, http://joearmendariz.org/ cheap viagra, http://cosmeticsculptra.com/ buy zolpidem, http://potagergardengirl.com/ quitting lexapro, http://collegetunnel.info/ vicoprofen and xanax taken together, http://creativespecial.com/ zithromax, 2010/04/01

 


Prev
   PHP 4.0 살펴보기 [28]

박우진
Next
   PHP의 역사

박우진


Copyright 1999-2021 Zeroboard / skin by madpark