在PHP中显示数组值 [英] Display array values in PHP

查看:131
本文介绍了在PHP中显示数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我用PHP工作的第一次,我试图来检索和显示数组的值。很多谷歌搜索后,唯一的方法我可以找到这个是的print_r 的var_dump var_export 。然而,所有这些方法返回的东西,看起来像这样:

So, I'm working with PHP for the first time and I am trying to retrieve and display the values of an array. After a lot of googling, the only methods I can find for this are print_r, var_dump or var_export. However, all of these methods return something that looks like this:

[a] => apple
[b] => banana
[c] => orange

我无法弄清楚如何风格这个outout。我需要抛开 [A] => 部分并添加逗号。我知道这一定是pretty简单的过程,但我一直无法追查演示如何做的文档。

I can't figure out how to style this outout. I need to strip away the [a] => part and add commas. I know this must be a pretty straightforward process but I haven't been able to track down any documentation that demonstrates how to do it.

推荐答案

循环在PHP。你必须遍历数组。

There is foreach loop in php. You have to traverse the array.

foreach($array as $key => $value)
{
  echo $key." has the value". $value;
}

如果您只是想值之间添加逗号,请考虑使用破灭

If you simply want to add commas between values, consider using implode

$string=implode(",",$array);
echo $string;

这篇关于在PHP中显示数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆