PDO FetchAll阵列 [英] PDO FetchAll Array

查看:55
本文介绍了PDO FetchAll阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道$ stmt-> fetchAll(PDO :: FETCH_ASSOC);将数组中的结果返回给变量,但是您将如何从数组中提取信息呢?假设该变量包含3000个条目.

I know that $stmt->fetchAll(PDO::FETCH_ASSOC); returns the result in an array to the variable, but how would you go around extracting the information from the array? Say the variable holds 3000 entries.

谢谢

推荐答案

如果您的意思是从$stmt->fetchAll(PDO::FETCH_ASSOC);返回的内容中提取信息,则需要将其设置为变量.

If you mean extract information from what $stmt->fetchAll(PDO::FETCH_ASSOC); returns, you need to set it to a variable.

$returned_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($returned_results as $key=>$result) {
     echo "<pre>"; var_dump($result); echo "</pre>";
}

这将转储每个结果,这将向您展示如何直接访问数组层次结构.
最终会变成这样:

This will dump every result, which will show you how to directly access the array hierarchy.
Which will end up being something like:

$returned_results[2]['somefield'];

这篇关于PDO FetchAll阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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