您好,欢迎访问三七文档
PHPPreviousPageNextPagePHP-PHPHTMLPHPPHP?php?PHP??(?php)?phpPHPHTMLHTMLPHPPHPHelloWorld?phpechoHelloWorld;PHPPHPechoprintechoHelloWorldPHPPHP///**/?php//Thisisacomment/*Thisisacommentblock*/PHPPreviousPageNextPagePHPPHP$PHP$var_name=value;PHP$?php$txt=HelloWorld!;$number=16;PHPLooselyTypedLanguagePHPPHPPHPPHP_$my_string$myStringPreviousPageNextPageSearch:PHPPHPPHPPreviousPageNextPagePHPPHPPHPHelloWorld$txt?php$txt=HelloWorld;echo$txt;HelloWorldConcatenationOperatorPHP(.)(.)?php$txt1=HelloWorld;$txt2=1234;echo$txt1..$txt2;HelloWorld1234$txt1$txt2strlen()strlen()Helloworld!?phpechostrlen(Helloworld!);12strpos()strpos()FALSEworld?phpechostrpos(Helloworld!,world);6world66701PHPStringPHPStringPHPPreviousPageNextPage.PHPPHP+Additionx=2x+24-Subtractionx=25-x3*Multiplicationx=4x*520/Division15/55/232.5%Modulus(divisionremainder)5%210%810%2120++Incrementx=5x++x=6--Decrementx=5x--x=4=|x=y|x=y+=|x+=y|x=x+y-=|x-=y|x=x-y*=|x*=y|x=x*y/=|x/=y|x=x/y.=|x.=y|x=x.y%=|x%=y|x=x%y==isequalto5==8returnsfalse!=isnotequal5!=8returnstrueisgreaterthan58returnsfalseislessthan58returnstrue=isgreaterthanorequalto5=8returnsfalse=islessthanorequalto5=8returnstrue&&andx=6y=3(x10&&y1)returnstrue||orx=6y=3(x==5||y==5)returnsfalse!notx=6y=3!(x==y)returnstruePreviousPageNextPagePHPIf……ElsePreviousPageNextPageifelseifelseif……elseelseifif……elseIf……Elseif……elseif(condition)codetobeexecutedifconditionistrue;elsecodetobeexecutedifconditionisfalse;Haveaniceweekend!Haveaniceday!?php$d=date(D);if($d==Fri)echoHaveaniceweekend!;elseechoHaveaniceday!;?php$d=date(D);if($d==Fri){echoHello!;echoHaveaniceweekend!;echoSeeyouonMonday!;}ElseIfelseifif(condition)codetobeexecutedifconditionistrue;elseif(condition)codetobeexecutedifconditionistrue;elsecodetobeexecutedifconditionisfalse;Haveaniceweekend!HaveaniceSunday!Haveaniceday!?php$d=date(D);if($d==Fri)echoHaveaniceweekend!;elseif($d==Sun)echoHaveaniceSunday!;elseechoHaveaniceday!;PHPSwitchPreviousPageNextPagePHPSwitchSwitchSwitchSwitchif..elseif..elseswitch(expression){caselabel1:codetobeexecutedifexpression=label1;break;caselabel2:codetobeexecutedifexpression=label2;break;default:codetobeexecutedifexpressionisdifferentfrombothlabel1andlabel2;}casecasebreakcasecasedefault?phpswitch($x){case1:echoNumber1;break;case2:echoNumber2;break;case3:echoNumber3;break;default:echoNonumberbetween1and3;}PHPPreviousPageNextPagePHPIDIDIDID1ID$names=array(Peter,Quagmire,Joe);2ID$names[0]=Peter;$names[1]=Quagmire;$names[2]=Joe;ID?php$names[0]=Peter;$names[1]=Quagmire;$names[2]=Joe;echo$names[1].and.$names[2].are.$names[0].'sneighbors;QuagmireandJoearePeter'sneighborsID1$ages=array(Peter=32,Quagmire=30,Joe=34);21$ages['Peter']=32;$ages['Quagmire']=30;$ages['Joe']=34;ID?php$ages['Peter']=32;$ages['Quagmire']=30;$ages['Joe']=34;echoPeteris.$ages['Peter'].yearsold.;Peteris32yearsold.1ID$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))2echoIs.$families['Griffin'][2].apartoftheGriffinfamily?;IsMeganapartoftheGriffinfamily?PHPPreviousPageNextPagePHPPHPwhiledo……whileforforeachwhilewhilewhile(condition)codetobeexecuted;i51?php$i=1;while($i=5){echoThenumberis.$i.;$i++;}do……whiledo……while-do{codetobeexecuted;}while(condition);ii5?php$i=0;do{$i++;echoThenumberis.$i.;}while($i5);forforfor(initialization;condition;increment){codetobeexecuted;}forinitializationincrementtruefalseHelloWorld!5?phpfor($i=1;$i=5;$i++){echoHelloWorld!;}foreachforeachvalue-foreach(arrayasvalue){codetobeexecuted;}?php$arr=array(one,two,three);foreach($arras$value){echoValue:.$value.;}PHPPreviousPageNextPagePHPPHP700PHPPHPPHPPHPfunction()-{-}-?phpfunctionwriteMyName(){echoDavidYang;}writeMyName();PHPPHP?phpfunctionwriteMyName(){echoDavidYang;}echoHelloworld!;echoMynameis;writeMyName();echo.That'sright,;writeMyName();echoismyname.;Helloworld!MynameisDavidYang.That'sright,DavidYangismyname.PHP-writeMyName()1?phpfunctionwriteMyName($fname){echo$fname.Yang.;}echoMynameis;writeMyName(David);echoMynameis;writeMyName(Mike);echoMynameis;writeMyName(John);MynameisDavidYang.MynameisMikeYang.MynameisJohnYang.2?phpfunctionwriteMyName($fname,$punctuation){echo$fname.Yang.$punctuation.;}echoMynameis;writeMyName(David,.);echoMynameis;writeMyName(Mike,!);echoMynameis;writeMyName(John,……);MynameisDavidYang.MynameisMikeYang!MynameisJohnYang……PHP-?phpfunctionadd($x,$y){$total=$x+$y;return$total;}echo1+16=.add(1,16);1+16=17PreviousPageNextPagePHPPreviousPageNextPagePHP$_GET$_POSTPHPName:Age:HTMLwelcome.phpwelcome.phpWelcome?phpecho$_POST[name];?.Youare?phpecho$_POST[age];?yearsold.WelcomeJohn.Youare28yearsold.PHP$_GET$_POSTPreviousPageNextPageSearch:PHP$_GETPreviousPageNextPage$_GETmethod=get$_GET$_GETHTTPGET$_GETmethod=getGET100Name:Age:URL=Peter&age=37welcome.php$_GET$_GETIDWel
本文标题:jsj_PHP基础
链接地址:https://www.777doc.com/doc-6226098 .html