PHP-cURL Adding entry to an array in a function not working -


I can get a proper response in function request_callback, so I thought it was just trivial to save the response in an array Associative_array [], although it only gives an entry, such as the array is wiped after every entry.

I

  & lt; Php # item number $ url1 = "http://api.guildwars2.com/v2/commerce/listings"; $ response1 = file_get_contents ($ url1); $ data1 = json_decode ($ response 1, true); # Recover item names and link function with numbers request_callback ($ response) {$ temporary_array = json_decode ($ response, true); $ Associative_array [] = array ('name' => $ temporary_array ['name'], 'id' = & gt; $ temporary_array ['id']); // array [] keeps the new entry at the end of the URL stack, faster array_push ($ array, new entry); Print_r ($ associative_array); Echo "\ n"; } # Multiple curl requests are required ("rollingcurl.php"); {$ Itemurl1 = "http://api.guildwars2.com/v2/items/{$data1[$$}}" for $ x ($ X = 0; $ x $ 5; $ x ++); $ Url [$ x] = $ itemurl1; } $ RC = new rollingcroll ("requestcale"); $ RC- & gt; Window_size = 20; Foreign currency ($ url $ url) {$ request = new rollingcurl request ($ url); $ RC - & gt; Plus ($ request); } $ Rc- & gt; carry about (); ? & Gt;    

Your array is local to your function, so resetting it to each call. Try adding a global announcement and you will get whatever you expect (all values);

  function request callback ($ response) {global $ associative_array; $ temporary_array = json_decode ($ response, true); $ Associative_array [] = array ('name' => $ temporary_array ['name'], 'id' = & gt; $ temporary_array ['id']); // array [] keeps the new entry at the end of the URL stack, faster array_push ($ array, new entry); Print_r ($ associative_array); Echo "\ n"; }    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -