下面的腳本顯然使用了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