php对象转数组问题,在线等

WBOY
Release: 2016-06-23 13:40:53
Original
986 people have browsed it

php对象转数组问题,下面$images是数组,实现将key和value变换。$images是对象的话该怎么做呢?在线等
function change($images,$a=0){
foreach($images as $key=>$value){
$images[$a][$value['picture_id']]=$value['local_path'];
$images[$a]['picture_id']=$value['picture_id'];
$a++;
}
return $images;
}

$arry=change($images);


回复讨论(解决方案)

PHP自带arrayObject类
$obj = new arrayObject ( $arr );
var_dump($obj);

数据库取数据吗,不用转换,直接foreach就可以,只不过对象用$obj->xxx来处理值

数据库取数据吗,不用转换,直接foreach就可以,只不过对象用$obj->xxx来处理值


你说的对,不过前端需要的字段不一样,需要foreach改名,已经做出来了
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template