输出(回声/打印)一切从一个PHP数组 [英] Output (echo/print) everything from a PHP Array

查看:133
本文介绍了输出(回声/打印)一切从一个PHP数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能回声或打印一个数组的全部内容,而无需指定数组的哪一部分?

Is it possible to echo or print the entire contents of an array without specifying which part of the array?

场景:我想回应一切从:

The scenario: I am trying to echo everything from:

while($row = mysql_fetch_array($result)){
echo $row['id'];
}

如果不指定身份证,而是输出数组的完整内容。

Without specifying "id" and instead outputting the complete contents of the array.

推荐答案

如果您想格式化输出你自己,只需添加另一个循环(的foreach)通过当前行中的内容进行迭代:

If you want to format the output on your own, simply add another loop (foreach) to iterate through the contents of the current row:

while ($row = mysql_fetch_array($result)) {
    foreach ($row as $columnName => $columnData) {
        echo 'Column name: ' . $columnName . ' Column data: ' . $columnData . '<br />';
    }
}

或者,如果你不关心格式,则使用在previous答案推荐的print_r功能。

Or if you don't care about the formatting, use the print_r function recommended in the previous answers.

while ($row = mysql_fetch_array($result)) {
    echo '<pre>';
    print_r ($row);
    echo '</pre>';
}

的print_r()仅打印键和阵列的值,相对的var_dump()伟驰也打印类型的阵列中的数据,即字符串,整数,双,等等。如果你真的关心数据类型 - 过度的print_r用var_dump()()

print_r() prints only the keys and values of the array, opposed to var_dump() whichs also prints the types of the data in the array, i.e. String, int, double, and so on. If you do care about the data types - use var_dump() over print_r().

这篇关于输出(回声/打印)一切从一个PHP数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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