PHP:回显数组只返回单词数组而不是其内容 [英] PHP: echoing array only returns the word array instead of its content
本文介绍了PHP:回显数组只返回单词数组而不是其内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对 PHP 很陌生,希望您能帮我解决这个问题.
I am very new to PHP and hope you can help me with this.
我正在从 SQL 获取一些数据并尝试创建一个我想在页面上回显的数组.
I am fetching some data from SQL and try to create an array that I want to echo on a page.
当我从以下 ($output
) 回显结果时,这只会返回单词array",而不是我尝试添加的项目.
When I echo the result from the following ($output
) then this only returns the word "array" insteaed of the items that I am trying to add to it.
谁能告诉我我在这里做错了什么并给我一个简短的解释?
$c = "";
$i = 0;
$arr = array();
$output = ''
foreach ($objNames->names as $names) {
$c = "<img src='images/photos/photo_" . str_replace(" ", "_", $names->member) . ".png' alt='' class='clickable flagLink trackHC' /> " . $names->member . " ";
array_push($arr, $c);
$i++;
}
if($i != 0) {
$output = $arr;
}
<div id="output"><?php echo $output; ?></div>
非常感谢您的帮助,迈克.
Many thanks for any help, Mike.
推荐答案
你不能只回显数组.
例如,您必须使用 foreach 循环遍历它:
You have to loop through it with a foreach for example:
$c = "";
$i = 0;
$arr = array();
$output = ''
foreach ($objNames->names as $names) {
$c = "<img src='images/photos/photo_" . str_replace(" ", "_", $names->member) . ".png' alt='' class='clickable flagLink trackHC' /> " . $names->member . " ";
array_push($arr, $c);
$i++;
}
if($i != 0) {
$output = $arr;
}
foreach($output as $row) {
?>
<div id="output"><?php echo $row; ?></div>
<?php
}
这应该对你有用!
这篇关于PHP:回显数组只返回单词数组而不是其内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文