PHP 数组遍历:使用 foreach 输出工具信息
可以使用 foreach 循环遍历数组,然后使用字符串拼接输出每个元素的键值对应的信息。
示例代码如下:
$tools = ['c' => 'Visual C', 'java' => 'exlipse', 'php' => 'nodepad'];
foreach ($tools as $key => $value) {
echo 'The ' . $value . ' is the tool of ' . $key . '\n';
}
输出结果如下:
The Visual C is the tool of c.
The exlipse is the tool of java.
The nodepad is the tool of php.
原文地址: https://www.cveoy.top/t/topic/lXoz 著作权归作者所有。请勿转载和采集!