我正在使用 curl 从网站获取一些数据。在我处理它之后,我设法让它进入这个状态:
Array (
[GraphicRiver] => Array ( [0] => stdClass Object
(
[id] => 698515
[item] => Alien Icons Set
[url] => http://graphicriver.net/item/alien-icons-set/698515
[user] => chaoscod3r
[thumbnail] => http://2.s3.envato.com/files/23574322/Thumb.jpg
[sales] => 5
[rating] => 0
[cost] => 5.00
[uploaded_on] => Mon Oct 24 17:16:20 +1100 2011
[tags] => alien icons, clean icons, easy editing, icons pack, minimalist icons pack, resizable, simple icons, vector icons, vector shapes
[category] => icons/miscellaneous
[live_preview_url] => http://3.s3.envato.com/files/23574321/Preview.jpg
)
)
)
但是我想要的不是那个stdClass对象而是数组,那么我该如何重写这种数组来制作那个对象和数组呢?
这是我用来获取上述内容的方法:
public function all_items_by_site($user_name) {
$items_by_marketplace = $this->user_items_by_site($user_name);
$marketplaces = array();
$items = array();
foreach ($items_by_marketplace as $key) {
$marketplaces[] = array(
'Marketplace' => $key->site,
'Items' => $key->items
);
}
foreach ($marketplaces as $key) {
$items[$key['Marketplace']] = $this->new_files_from_user($user_name, $key['Marketplace']);
}
return $items;
}
我正在使用这个 api 包装器作为我想要开发的基本 api 包装器:https ://github.com/JeffreyWay/Envato-Marketplace-API-Wrapper-in-PHP 。