PHP100 2019-03-28
PHPer都知道PHP是不支持字面量了,至少目前版本都不支持。比如,在JS中可以这样定义object
代码如下:
var o = { 'name' : 'qttc' , 'url' : 'www.jb51.net' }; alert(o.name);
代码如下:
o = { 'name' : 'qttc' , 'url' : 'www.jb51.net' } print o['name']
代码如下:
$a = { "name" : "qttc", "url" : "www.jb51.net" };
代码如下:
[root@lee www]# php a.php PHP Parse error: syntax error, unexpected '{' in /data0/htdocs/www/a.php on line 4
代码如下:
$a = '{ "name" : "qttc", "url" : "www.jb51.net" }'; $a = json_decode($a); print_r($a);
代码如下:
[root@lee www]# php a.php stdClass Object ( [name] => qttc [url] => www.jb51.net )
代码如下:
$a = '{ "name" : "qttc", "url" : "www.jb51.net" , "arr":["zhangsan","lisi"] }'; $a = json_decode($a); print_r($a);
代码如下:
[root@lee www]# php a.php stdClass Object ( [name] => qttc [url] => www.jb51.net [arr] => Array ( [0] => zhangsan [1] => lisi ) )
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh