Linux 拨号vps windows公众号手机端

php关联数组如何输出

lewis 9年前 (2016-12-14) 阅读数 8 #程序编程
文章标签 PHP

关联数组可以通过foreach循环遍历输出,也可以通过键值来访问特定的值。以下是一些例子:

  1. 使用foreach循环输出关联数组的所有值:
$fruits = array("apple" => "red", "banana" => "yellow", "orange" => "orange");

foreach($fruits as $key => $value) {
    echo "The color of $key is $value <br>";
}

输出结果:

The color of apple is red
The color of banana is yellow
The color of orange is orange
  1. 使用键值来访问特定的值:
$fruits = array("apple" => "red", "banana" => "yellow", "orange" => "orange");

echo "The color of apple is " . $fruits["apple"];

输出结果:

The color of apple is red

通过以上方法,可以方便地输出关联数组的值。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门