PHP的"=>"符号

在PHP中"=>"符号是用于在数组中分配键值对,主要在关联数组中使用。【视频教程推荐:PHP教程】

基本句式:

key => value

说明:"=>"符号的左侧值称为键,右侧值称为键值。

“=>"符号的使用示例

下面通过简单代码示例来介绍"=>"符号的使用方法。

示例1:使用“=>”符号创建关联数组

<"content-type:text/html;charset=utf-8"); 
$subject = array( "Maths" => 95, 
     "Physics" => 90, 
     "Chemistry" => 96, 
     "English" => 93, 
     "Computer" => 98 
   ); 
  
echo "学生成绩:<br><br>"; 
echo "数学:" . $subject["Maths"], "<br>"; 
echo "物理:" . $subject["Physics"], "<br>"; 
echo "化学:" . $subject["Chemistry"], "<br>"; 
echo "英语:" . $subject["English"], "<br>"; 
echo "计算机:" . $subject["Computer"], "<br>"; 
"//img.jbzj.com/file_images/article/201903/201903010841261.jpg" alt="" />

示例2:使用“=>”符号创建数字索引数组

<"0" => 7, 
    "1" => 10, 
    "2" => 8, 
    "3" => 5 
  ); 
foreach($arr as $key => $value) { 
 echo $key . " => " . $value . "<br>"; 
} 
"//img.jbzj.com/file_images/article/201903/201903010841262.jpg" alt="" />

示例3:用于在不使用“=>”符号的情况下分配数字索引

<"content-type:text/html;charset=utf-8"); 
$name = array("Zack", "Anthony", 
  "Ram", "Salim", "Raghav"); 
 
foreach($name as $key => $value) { 
 echo $key . " => " . $value . "<br>"; 
} 
"//img.jbzj.com/file_images/article/201903/201903010841263.jpg" alt="" />

标签:
PHP,=>

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“PHP中“=>”

暂无“PHP中“=>”评论...