热卖商品
新闻详情
PHP: Array 数组 - Manual
来自 : www.php.net/manual/zh/language
发布时间:2021-03-25
?php
//Showallerrors
error_reporting(E_ALL);
$arr=array(\'fruit\'= \'apple\',\'veggie\'= \'carrot\');
//Correct
print$arr[\'fruit\'];//apple
print$arr[\'veggie\'];//carrot
//Incorrect.ThisworksbutalsothrowsaPHPerroroflevelE_NOTICEbecause
//ofanundefinedconstantnamedfruit
//
//Notice:Useofundefinedconstantfruit-assumed\'fruit\'in...
print$arr[fruit];//apple
//Thisdefinesaconstanttodemonstratewhat\'sgoingon.Thevalue\'veggie\'
//isassignedtoaconstantnamedfruit.
define(\'fruit\',\'veggie\');
//Noticethedifferencenow
print$arr[\'fruit\'];//apple
print$arr[fruit];//carrot
//Thefollowingisokay,asit\'sinsideastring.Constantsarenotlookedfor
//withinstrings,sonoE_NOTICEoccurshere
print\"Hello$arr[fruit]\";//Helloapple
//Withoneexception:bracessurroundingarrayswithinstringsallowsconstants
//tobeinterpreted
print\"Hello{$arr[fruit]}\";//Hellocarrot
print\"Hello{$arr[\'fruit\']}\";//Helloapple
//Thiswillnotwork,andwillresultinaparseerror,suchas:
//Parseerror:parseerror,expectingT_STRING\'orT_VARIABLE\'orT_NUM_STRING\'
//Thisofcourseappliestousingsuperglobalsinstringsaswell
print\"Hello$arr[\'fruit\']\";
print\"Hello$_GET[\'foo\']\";
//Concatenationisanotheroption
print\"Hello\".$arr[\'fruit\'];//Helloapple
?
自5.4 起可以使用短数组定义语法,用[]替代array()。 示例#1 一个简单数组 <?php $array= array( "foo"=>"bar", "bar"=>"foo", ...PHP: Array 数组
//Showallerrors
error_reporting(E_ALL);
$arr=array(\'fruit\'= \'apple\',\'veggie\'= \'carrot\');
//Correct
print$arr[\'fruit\'];//apple
print$arr[\'veggie\'];//carrot
//Incorrect.ThisworksbutalsothrowsaPHPerroroflevelE_NOTICEbecause
//ofanundefinedconstantnamedfruit
//
//Notice:Useofundefinedconstantfruit-assumed\'fruit\'in...
print$arr[fruit];//apple
//Thisdefinesaconstanttodemonstratewhat\'sgoingon.Thevalue\'veggie\'
//isassignedtoaconstantnamedfruit.
define(\'fruit\',\'veggie\');
//Noticethedifferencenow
print$arr[\'fruit\'];//apple
print$arr[fruit];//carrot
//Thefollowingisokay,asit\'sinsideastring.Constantsarenotlookedfor
//withinstrings,sonoE_NOTICEoccurshere
print\"Hello$arr[fruit]\";//Helloapple
//Withoneexception:bracessurroundingarrayswithinstringsallowsconstants
//tobeinterpreted
print\"Hello{$arr[fruit]}\";//Hellocarrot
print\"Hello{$arr[\'fruit\']}\";//Helloapple
//Thiswillnotwork,andwillresultinaparseerror,suchas:
//Parseerror:parseerror,expectingT_STRING\'orT_VARIABLE\'orT_NUM_STRING\'
//Thisofcourseappliestousingsuperglobalsinstringsaswell
print\"Hello$arr[\'fruit\']\";
print\"Hello$_GET[\'foo\']\";
//Concatenationisanotheroption
print\"Hello\".$arr[\'fruit\'];//Helloapple
?
自5.4 起可以使用短数组定义语法,用[]替代array()。 示例#1 一个简单数组 <?php $array= array( "foo"=>"bar", "bar"=>"foo", ...PHP: Array 数组
本文链接: http://array.immuno-online.com/view-770973.html
发布于 : 2021-03-25
阅读(0)
最新动态
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
公司介绍
品牌分类
联络我们