Beb*_*bus 0 php arrays function
以下函数仅返回数组的最后一行:
function myFunc () {
$sql = mySql();
$stid = oci_parse(getConnect(),$sql);
// runs the query above
oci_execute($stid);
if (oci_execute($stid)) {
while ($row =oci_fetch_array($stid,OCI_ASSOC+OCI_RETURN_NULLS)) {
$out1 = "";
foreach($row as $column =>$entry)
$out1 .= $entry;
$output = $out1;
//var_dump($output); - here I can see all array elements
}
return($output);
}
else return "No Oracle connection";
}
Run Code Online (Sandbox Code Playgroud)
var_dump()显示所有数组元素,但该函数仅显示数组的最后一行.这是因为功能的回归吗?我是否必须返回一个数组来获取所有数组元素?如何将所有数组元素放在一个字符串中?
您$output在每次循环迭代中重写.您需要将这些值存储在数组中(或根据您最终需要的内容将它们附加到它们):
$output = array();
while ($row = oci_fetch_array($stid,OCI_ASSOC+OCI_RETURN_NULLS)) {
$out1 = "";
foreach($row as $column =>$entry) {
$out1 .= $entry;
}
$output[] = $out1;
}
return($output);
Run Code Online (Sandbox Code Playgroud)
这个函数有点复杂,我很确定这可以大大简化,从查询开始.
| 归档时间: |
|
| 查看次数: |
979 次 |
| 最近记录: |