Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Odwołanie do elementu tablicy
Forum PHP.pl > Forum > PHP
tskalar
Witam,
w jaki sposób odwolac się do elementu [product_id]:
  1. print_r(json_decode($data));

drukuje:
stdClass Object
(
[count] => 1
[products] => Array
(
[0] => stdClass Object
(
[products_id] => 10
[products_name] => Groszek marynowany
[products_description_short] =>
[products_description] =>
....
próbowałem tak:
  1. echo $data[products][0][products_id];


ale nie działa.
timon27
echo $data->products[0]->products_id

Chyba. Sprawdź.
tskalar
Nie działa niestety.

Pobierane dane:
  1. $postData = array(
  2. 'key' => 'xxxxxxxxxxxxxxxxxxxxxxxx',
  3. 'viewType' => 'json',
  4. 'module' => 'products',
  5. 'method' => 'selectIds',
  6. 'parameters' => array(
  7. 'products_id' => array(10)
  8. )
  9. );
  10.  
  11. $postData = http_build_query($postData);
  12. $ch = curl_init('http://api2.redcart.pl/');
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  14. curl_setopt($ch, CURLOPT_POST, 1);
  15. curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
  16. $data = curl_exec($ch);
  17. curl_close($ch);
  18.  
  19.  
  20. echo"<pre>";
  21. print_r(json_decode($data));
  22. echo"</pre>";


Proszę o podpowiedź jak odwołać się do elementu [products_id]

stdClass Object
(
[count] => 1
[products] => Array
(
[0] => stdClass Object
(
[products_id] => 10
[products_name] => Groszek marynowany
[products_description_short] =>
[products_description] =>
Pyton_000
Cytat
print_r(json_decode($data, true));


Cytat
print_r(json_decode($data, true));
tskalar
drukuje:
CODE

Array
(
[count] => 1
[products] => Array
(
[0] => Array
(
[products_id] => 10
[products_name] => Groszek marynowany
[products_description_short] =>
[products_description] =>



Dzięki Pyton_000 smile.gif działa.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.