您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php object或者array怎么转换成string

2025/11/18 12:36:48发布24次查看
php object或者array如何转换成string
做php数据库查询的时候有两个函数
oci_fetch_object和oci_fetch_array(),分别返回object和array类型的返回值,我现在需要一个string类型的,如何转换?
$results = [;
$row = oci_fetch_array($stmt);    $results += ???   $results = ];
------最佳解决方案--------------------
while($row = oci_fetch_array($stmt)) {
 $result[] = $row;
}
$result = json_encode($result);
------其他解决方案--------------------
你可能需要的是 json_encode
------其他解决方案--------------------
引用:你可能需要的是 json_encode
我试过,不行。。。
其实我的目的就是要把oci查询的返回值变成json串
------其他解决方案--------------------
看你的格式,你是想把object或者是array转化为json格式吧。。
楼上正解,转化为json是json_encode,json转为array是json_decode
如果想自己拼接也可以啊。数组转化为string,直接用implode好了
------其他解决方案--------------------
贴出楼主的数据
------其他解决方案--------------------
$results = [;
$usercount = 0;
$row = oci_fetch_array($stmt);
if($row){
$results += $row;
$usercount++;
}
while (1) {
$row = oci_fetch_array($stmt);
if(!$row) break;
$results += ,+$row; 
    $usercount++;
}
$results += ];
这个是我的代码,得出的$results是0而不是json数组,其中查询是有多条返回值的
------其他解决方案--------------------
引用:while($row = oci_fetch_array($stmt)) {
 $result[] = $row;
}
$result = json_encode($result);
这样改后提示cannot use a scalar value as an array in,然后$result=“”
------其他解决方案--------------------
你把你原来的 $results = [; 删掉啊!
------其他解决方案--------------------
引用:你把你原来的 $results = [; 删掉啊!
删掉了,只写
while($row = oci_fetch_array($stmt)) {
 $result[] = $row;
}
$result = json_encode($result);
这一段来着,然后返回$result
$result[] = $row;提示cannot use a scalar value as an array in
------其他解决方案--------------------
引用:你把你原来的 $results = [; 删掉啊!
可以了,刚刚发现在函数开始有个$result的定义来着,删掉就可以了
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product