PHP:回声数组只返回字数组而不是其内容 [英] PHP: echoing array only returns the word array instead of its content

查看:151
本文介绍了PHP:回声数组只返回字数组而不是其内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的PHP,希望你能帮助我。

我从SQL获取一些数据,并尝试创建一个我想在页面上回显的数组。

当我回应下面的结果( $ output )时,只返回单词array我试图添加到它的项目。



是否有人能告诉我我在做什么错误,并给我一个简短的解释?

  $ c =; 
$ i = 0;
$ arr = array();
$ output =''
foreach($ objNames->名称为$ names){
$ c =< img src ='images / photos / photo_。 str_replace(,_,$ names->成员)。 .pngalt ='class ='clickable flagLink trackHC'/>& nbsp; 。 $ names->成员。 & nbsp;& nbsp;;
array_push($ arr,$ c);
$ i ++;

if($ i!= 0){
$ output = $ arr;
}


< div id =output><?php echo $ output; ?>< / DIV>

非常感谢您的帮助,Mike。

解决方案

你不能只回显数组。



例如通过它foreach:

  $ c =; 
$ i = 0;
$ arr = array();
$ output =''
foreach($ objNames->名称为$ names){
$ c =< img src ='images / photos / photo_。 str_replace(,_,$ names->成员)。 .pngalt ='class ='clickable flagLink trackHC'/>& nbsp; 。 $ names->成员。 & nbsp;& nbsp;;
array_push($ arr,$ c);
$ i ++;

if($ i!= 0){
$ output = $ arr;
}

foreach($ output as $ row){
?>
< div id =output><?php echo $ row; ?>< / DIV>
<?php
}

这应该适合您! p>

I am very new to PHP and hope you can help me with this.

I am fetching some data from SQL and try to create an array that I want to echo on a page.

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.

Can someone tell me what I am doing wrong here and provide me a short explanation as well ?

$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' />&nbsp;" . $names->member . " &nbsp;&nbsp;";
    array_push($arr, $c);
    $i++;
}
if($i != 0) {
    $output = $arr;
}


<div id="output"><?php echo $output; ?></div>

Many thanks for any help, Mike.

解决方案

You cant just echo arrays.

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' />&nbsp;" . $names->member . " &nbsp;&nbsp;";
    array_push($arr, $c);
    $i++;
}
if($i != 0) {
    $output = $arr;
}

foreach($output as $row) {
?>
    <div id="output"><?php echo $row; ?></div>
<?php
}

This should work for you!

这篇关于PHP:回声数组只返回字数组而不是其内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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