PHP数组定义
一维数组:
1、$a=array(1,2,4,5,6);
2、$a= Array("cec"=>"cecValue","logo"=>"logoValue");
3、$a=["Volvo","BMW","SAAB"]; //PHP 5.4以后版本支持
4、$cars=[];
$cars[0] = "Volvo";
$cars[1] = "BMW";
$cars[2] = "SAAB";
二维数组的区别:
$a=array(
array(),
array())
关联数组:
$a=array(
‘a‘=>array(),
‘b‘=>array())
JS中的数组定义:
1、var a=[1,2,3,4];
2、var a=new Array();
3、var a =[ [12,3,4,5,5],[1,2,3,4,5] ];
4、var china= {beijing:{name:"北京",area:"16000",haidian:{name:"海淀区"}},
引用:alert(china.beijing.haidian.name);
JSON中的使用
PHP:
使用“json_encode()” 和 "json_decode()" 进行串行化和反串行化
例子:
$a
=
array
(
‘a‘
=>
‘Apple‘
,
‘b‘
=>
‘banana‘
,
‘c‘
=>
‘Coconut‘
);
$s
= json_encode(
$a
);
echo $s //输出结果:{"a":"Apple","b":"banana","c":"Coconut"}
$o
= json_decode(
$s
); //反串行化
JS:
使用“JSON.parse()”和“JSON.stringify()”进行串行化和反串行化
例子:
var jsonstr = ‘{"name":"jifeng","company":"taobao","value":++value}‘; var arrJson arrJSON.parse(jsonstr) //反串行化