PHP Backend Application(1)Env and PHP Knowledge

本文详细介绍了PHP开发的基础知识,包括版本检查、类型系统、基本操作、数组使用、环境配置等核心内容,提供了丰富的示例代码和实用技巧,旨在帮助开发者深入理解并熟练运用PHP进行高效开发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PHP Backend Application(1)Env and PHP Knowledge

Check the PHP version
> php --version
PHP 5.6.16 (cli) (built: Dec 26 2015 18:37:18)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

The comments style is similar to Java, file starter and end are like this
<?php
echo "php runs first!";
echo "\nrecall my php knowledge"; // one line comments
/*
this is how th comments go in java
*/
?>

Types
Four scalar type: boolean, integer, float, string
Two compound types: array, object
Two special types: resource, NULL

Check the type and get type
<?php
$a_boolean = TRUE;
$a_string = "foo";

echo gettype($a_boolean);
echo "\n";
echo var_dump($a_string);
echo is_string($a_string);
echo "\n";

?>

console output is as follow:
boolean
string(3) "foo"
1

Cast other value to boolean
var_dump((bool) 1); // bool(true)
var_dump((bool) -2); // bool(true)

Automatically covert the int to float
$large_number = 2147483647;

var_dump($large_number); // int(2147483647)

$large_number = 2147483648;
var_dump($large_number); // float(2147483648)

Single Quoted for String
// Outputs: This will not expand: \n a newline

echo 'This will not expand: \n a newline';

// Outputs: Variables do not $expand $either
echo 'Variables do not $expand $either';

Double Quoted

Heredoc
$str = <<<EOD

Example of string
spanning multiple lines
using heredoc syntax.
EOD;

nowdoc is single quoted heredoc
echo <<<'EOT'

My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should not print a capital 'A': \x41
EOT;

Environment and Types
> cat type.php
<?php
$arr = array("foo"=>1, 12=>true);
echo gettype($arr[12])."\n";
echo $arr[12]."\n";
?>

> php type.php
boolean
1

unset($arr[5]); // This removes the element from the array
unset($arr); // This deletes the whole array

As mentioned above, if no key is specified, the maximum of the existing integer indices is taken, and the new key will be that maximum value plus 1.

A lot of useful array operations are here http://sillycat.iteye.com/blog/1543227

The unset() function allows removing keys from an array. Be aware that the array will not be reindexed.

The array_values() function can be used to 'remove and shift'.
$a = array(1 => 'one', 2 => 'two', 3 => 'three');
unset($a[2]);
/* will produce an array that would have been defined as
$a = array(1 => 'one', 3 => 'three');
and NOT
$a = array(1 => 'one', 2 =>'three');
*/
print_r($a);
echo "<br />";
$b = array_values($a);
// Now $b is array(0 => 'one', 1 =>'three')
print_r($b);

http://sillycat.iteye.com/blog/2302285

Code Standard
http://sillycat.iteye.com/blog/2194084

PHP with FPM
http://sillycat.iteye.com/blog/2223621

PHP Lumen
http://sillycat.iteye.com/blog/2238841
http://sillycat.iteye.com/blog/2239826

Install latest PHP on EC2
http://sillycat.iteye.com/blog/2302287

UNIT Test
http://sillycat.iteye.com/blog/2302288

> phpunit --version
PHPUnit 5.1.3 by Sebastian Bergmann and contributors.

References:
PHP Basic1 ~ 3
http://sillycat.iteye.com/blog/768664
http://sillycat.iteye.com/blog/769110
http://sillycat.iteye.com/blog/770369

PHP 1~ 8
http://sillycat.iteye.com/blog/1543227
http://sillycat.iteye.com/blog/2066063
http://sillycat.iteye.com/blog/2302285
http://sillycat.iteye.com/blog/2194084
http://sillycat.iteye.com/blog/2223621
http://sillycat.iteye.com/blog/2238841
http://sillycat.iteye.com/blog/2239826

Language References
http://php.net/manual/en/langref.php

PHP Env
http://sillycat.iteye.com/blog/1634562
http://sillycat.iteye.com/blog/1638638
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值