PHP回声返回单词“数组” [英] PHP echo returning the word 'Array'

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

问题描述

一直潜伏#2很长一段时间,但是这是我的第一篇文章。我收到有关显示这是应该由MySQL查询来填充数组的错误。 echo函数只是返回 ArrayArrayArray 不是什么应该在那里。 MySQL查询是比较表单输入(变量 $数据)。

 < PHP
$数据= $ _ POST [搜索];
全球$的数据;//创建连接
$ CON = mysqli_connect(XXXXX,XXXXXX,XXXXX,XXXXX);//检查连接
如果(mysqli_errno($ CON)){
    回声无法连接到数据库;
}
//执行查询进行比较,并返回结果
$ result_array =阵列();
$查询=选择URL从数据中其中URL LIKE'%$数据%';
$结果= mysqli_query($ CON,$查询);
// while循环返回所有可比较的结果
    而($行= mysqli_fetch_array($结果)){ $ result_array [] = $行['URL']; 回声$ result_array;
}
?>


解决方案

回声 将打印字符串,请尝试使用类似 的print_r() 的var_dump() 而不是

示例

 回声'< pre>';
的print_r($ result_array);
呼应'< / pre>';

< pre> 将允许阵列更容易阅读

Been lurking on Stackoverflow for a long time but this is my first post. I am receiving a error related to displaying an array which is supposed to be populated by a mysql query. The echo function just returns ArrayArrayArray instead of what is supposed to be there. The mysql query is comparing a form input (the variable $data) .

<?php
$data = $_POST["search"];
global $data;

// Create Connection
$con = mysqli_connect(xxxxx,xxxxxx,xxxxx,xxxxx);

// Check Connection
if (mysqli_errno($con))

{
    echo "Failed To Connect To The Database" ;
}


//Perform Query To Compare And Return Results
$result_array = array();
$query = " SELECT url FROM data WHERE url LIKE '%$data%' "  ;
$result = mysqli_query($con, $query);
// While Loop To Return All Comparable Results
    while ($row = mysqli_fetch_array($result)) {

 $result_array[] = $row['url'];

 echo $result_array ;


}
?>

解决方案

echo will print a string, try using something like print_r() or var_dump() instead

Example

echo '<pre>';
print_r($result_array);
echo '</pre>';

<pre> will allow for easier reading of the array

这篇关于PHP回声返回单词“数组”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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