4000-520-616
欢迎来到免疫在线!(蚂蚁淘生物旗下平台)  请登录 |  免费注册 |  询价篮
主营:原厂直采,平行进口,授权代理(蚂蚁淘为您服务)
咨询热线电话
4000-520-616
当前位置: 首页 > 新闻动态 >
热卖商品
新闻详情
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 数组

本文链接: http://array.immuno-online.com/view-747767.html

发布于 : 2021-03-25 阅读(0)
公司介绍
品牌分类
联络我们
服务热线:4000-520-616
(限工作日9:00-18:00)
QQ :1570468124
手机:18915418616