Home > Backend Development > PHP Tutorial > php对象转数组有关问题

php对象转数组有关问题

WBOY
Release: 2016-06-13 12:14:13
Original
1367 people have browsed it

php对象转数组问题,在线等
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来处理值

Related labels:
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