下面的脚本显然使用了http://www.hasoffers.com/wiki/Offer:create中记录的API。问题有(至少)两个部分:a)如何在一个数组中存储多个数据集。 b)该API是否接受它....array只选取要存储的最后一个值
当我运行它只存储里面“数据”我怎样才能得到它在一次存储更多数据的最后一个值的脚本?
下面的代码有例如2个值。一个是LOLO,另一个是LELE。 输出仅显示值LELE。
这是代码。
<?php
header('Content-type: application/json');
$base = 'http://api.hasoffers.com/Api?';
$params = array(
'Format' => 'json'
,'Target' => 'Offer'
,'Method' => 'create'
,'Service' => 'HasOffers'
,'Version' => 2
,'NetworkId' => 'demo'
,'NetworkToken' => '....'
,'data' => array(
'name' => 'LOLO'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
,'name' => 'LELE'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
)
);
$url = $base . http_build_query($params);
$result = file_get_contents($url);
print_r(json_decode($result));
?>
,这是输出
[request] => stdClass Object
(
[Target] => Offer
[Format] => json
[Service] => HasOffers
[Version] => 2
[Method] => create
[NetworkId] => demo
[NetworkToken] => NETU2nzMw8AYS6EGgjFrjGR88GcSiF
[data] => stdClass Object
(
[name] => LELE
[description] => test
[offer_url] => http://google.nl
[preview_url] => http://google.nl
[expiration_date] => 08-08-2013
)
)
你有只有一个元素的数组,里面的键值重复,所以最后一个被记住。 – 2013-02-28 09:07:41
但是当我运行脚本它显示我[0] => ...和[1] => ...我怎么能做到这一点,而没有得到这个值因为Hasoffer平台的API只接受'data'=> [名称] ..不是'data'=> [0] => [name] – 2013-02-28 09:21:56
答案可能是(并且已经浏览了我认为是的api文档):您必须发送两个单独的请求,两个创建两个单独的提议。 – VolkerK 2013-02-28 09:33:19