PHP:警告:sort()期望参数1为数组,给定资源 [英] PHP: Warning: sort() expects parameter 1 to be array, resource given
本文介绍了PHP:警告:sort()期望参数1为数组,给定资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用sort()函数安排表列表的数组,但是我得到了同样的警告 我的代码如下:
I wanted to arrange the array of table list with sort() function but i am getting same kind of warning my code as follows :
<?PHP
require_once("lib/connection.php");
$result = mysql_query("SHOW TABLES FROM `st_db_1`");
sort($result);
foreach ($result as $result){
echo $result ;
}
?>
我得到的警告是:
Warning: sort() expects parameter 1 to be array, resource given in C:\wamp\www\Copy (4) of st_db_1\test_2.php on line 9
Warning: Invalid argument supplied for foreach() in C:\wamp\www\Copy (4) of st_db_1\test_2.php on line 10
推荐答案
我没有提供可想象的最有效的代码,但这应该可以清楚说明正在发生的事情并解决您的问题:
I'm not providing the most efficient code imaginable, but this should make it clear what's going on and solve your problem:
$result = mysql_query("SHOW TABLES FROM `st_db_1`");
$my_array_of_table_names = array();
while ( $row = mysql_fetch_array($result, MYSQL_NUM)) {
$my_array_of_table_names[] = $row[0];
}
sort($my_array_of_table_names);
foreach ($my_array_of_table_names as $table_name){
echo "$table_name\n";
}
这篇关于PHP:警告:sort()期望参数1为数组,给定资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文