PHP:如何从数组中回显字符串?
我一直试图从数组中回显字符串,我得到的只是“数组”作为文本。
这是数组:
$_SESSION['lista'][] = array(
'articulo' => $articulo,
'precio' => $precio,
'cantidad' => $cantidad);
这是回显:
echo "1. ".$_SESSION['lista'][0][0]." ".$_SESSION['lista'][0][1]." unidades".", ".$_SESSION['lista'][0][2]." CRC.";
当前输出是:
1. Array Array unidades, Array CRC.
I'm stuck trying to echo strings from an array, all I get is "Array" as text.
This is the array:
$_SESSION['lista'][] = array(
'articulo' => $articulo,
'precio' => $precio,
'cantidad' => $cantidad);
This is the echo:
echo "1. ".$_SESSION['lista'][0][0]." ".$_SESSION['lista'][0][1]." unidades".", ".$_SESSION['lista'][0][2]." CRC.";
The current output is:
1. Array Array unidades, Array CRC.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
删除 [] 所以它看起来像这些
并将session_start()放在起始行;
访问数组:
Remove [] so it looks like these
And put session_start() at starting line;
To access the array:
您无法使用数字键作为偏移量来访问关联数组成员。
试试这个...
当您尝试将
array
隐式转换为字符串,例如使用echo
。You can't access an associative array member with a numerical key as an offset.
Try this...
An
array
's to string type method is called (and returnsArray
) when you try to implicitly convert it to a string, e.g. withecho
.看看 print_r 以及 var_dump 等。如手册中所述,这些函数以人类可读的格式打印数组/对象的内容。
Take a look at print_r along with var_dump etc. As stated in the manual, these functions print the contents of arrays/objects in human readable format.