PHP Backend Application(1)Env and PHP Knowledge
PHPBackendApplication(1)EnvandPHPKnowledge
CheckthePHPversion
>php--version
PHP5.6.16(cli)(built:Dec26201518:37:18)
Copyright(c)1997-2015ThePHPGroup
ZendEnginev2.6.0,Copyright(c)1998-2015ZendTechnologies
withZendOPcachev7.0.6-dev,Copyright(c)1999-2015,byZendTechnologies
withXdebugv2.2.5,Copyright(c)2002-2014,byDerickRethans
ThecommentsstyleissimilartoJava,filestarterandendarelikethis
<?php
echo"phprunsfirst!";
echo"\nrecallmyphpknowledge";//onelinecomments
/*
thisishowthcommentsgoinjava
*/
?>
Types
Fourscalartype:boolean,integer,float,string
Twocompoundtypes:array,object
Twospecialtypes:resource,NULL
Checkthetypeandgettype
<?php
$a_boolean=TRUE;
$a_string="foo";
echogettype($a_boolean);
echo"\n";
echovar_dump($a_string);
echois_string($a_string);
echo"\n";
?>
consoleoutputisasfollow:
boolean
string(3)"foo"
1
Castothervaluetoboolean
var_dump((bool)1);//bool(true)
var_dump((bool)-2);//bool(true)
Automaticallycoverttheinttofloat
$large_number=2147483647;
var_dump($large_number);//int(2147483647)
$large_number=2147483648;
var_dump($large_number);//float(2147483648)
SingleQuotedforString
//Outputs:Thiswillnotexpand:\nanewline
echo'Thiswillnotexpand:\nanewline';
//Outputs:Variablesdonot$expand$either
echo'Variablesdonot$expand$either';
DoubleQuoted
Heredoc
$str=<<<EOD
Exampleofstring
spanningmultiplelines
usingheredocsyntax.
EOD;
nowdocissinglequotedheredoc
echo<<<'EOT'
Mynameis"$name".Iamprintingsome$foo->foo.
Now,Iamprintingsome{$foo->bar[1]}.
Thisshouldnotprintacapital'A':\x41
EOT;
EnvironmentandTypes
>cattype.php
<?php
$arr=array("foo"=>1,12=>true);
echogettype($arr[12])."\n";
echo$arr[12]."\n";
?>
>phptype.php
boolean
1
unset($arr[5]);//Thisremovestheelementfromthearray
unset($arr);//Thisdeletesthewholearray
Asmentionedabove,ifnokeyisspecified,themaximumoftheexistingintegerindicesistaken,andthenewkeywillbethatmaximumvalueplus1.
Theunset()functionallowsremovingkeysfromanarray.Beawarethatthearraywillnotbereindexed.
Thearray_values()functioncanbeusedto'removeandshift'.
$a=array(1=>'one',2=>'two',3=>'three');
unset($a[2]);
/*willproduceanarraythatwouldhavebeendefinedas
$a=array(1=>'one',3=>'three');
andNOT
$a=array(1=>'one',2=>'three');
*/
print_r($a);
echo"<br/>";
$b=array_values($a);
//Now$bisarray(0=>'one',1=>'three')
print_r($b);
CodeStandard
PHPwithFPM
PHPLumen
InstalllatestPHPonEC2
UNITTest
>phpunit--version
PHPUnit5.1.3bySebastianBergmannandcontributors.
References:
PHPBasic1~3
PHP1~8
LanguageReferences
http://php.net/manual/en/langref.php
PHPEnv
相关推荐
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh