如何回显数组 [英] How to echo an array

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

问题描述

这不是我以前从来没有做过,但由于某种原因,这次不会工作......我只是从函数中返回数组

  //调用函数来创建结果数组
$ specs = giveData();

我想用这种方式输出数据:

 < b> lenght:< / b><?php echo $ specs [0] ['lenght']; ?> 

我已经尝试了var_dump,它向我展示了数组中的数据,也用print_r工作。 p>

编辑:我更新了代码的工作方式。

解决方案

不确定是否需要数组元素的数量:

  echo count($ specs); 

或迭代您的数组:

  foreach($ specs as $ key => $ value){
echo$ key:$ value< br />;
}


It's not like I've never done it before, but for some reason it won't work this time... I'm just returnin an array from a function

//Call Function to create the result array
$specs = giveData();

and I'm trying to output the data with echo this way:

<b>lenght:</b><?php echo $specs[0]['lenght']; ?>

I already tried var_dump and it shows me the data in the array, also with print_r works.

EDIT: I updated the code the way it works for me.

解决方案

not sure if you want the number of elements of the array :

echo count($specs);

or iterate over your array :

foreach($specs as $key => $value){
    echo "$key : $value<br/>";
}

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

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