Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Odwołanie do elementu tablicy, Tablice wielowymiarowe
tskalar
post 22.02.2014, 20:27:50
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 22.02.2014

Ostrzeżenie: (0%)
-----


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.
Go to the top of the page
+Quote Post
timon27
post 22.02.2014, 20:49:53
Post #2





Grupa: Zarejestrowani
Postów: 578
Pomógł: 69
Dołączył: 15.04.2007
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


echo $data->products[0]->products_id

Chyba. Sprawdź.

Ten post edytował timon27 22.02.2014, 20:51:22
Go to the top of the page
+Quote Post
tskalar
post 22.02.2014, 21:09:37
Post #3





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 22.02.2014

Ostrzeżenie: (0%)
-----


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] =>
Go to the top of the page
+Quote Post
Pyton_000
post 22.02.2014, 21:35:03
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Cytat
print_r(json_decode($data, true));


Cytat
print_r(json_decode($data, true));
Go to the top of the page
+Quote Post
tskalar
post 27.02.2014, 01:13:47
Post #5





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 22.02.2014

Ostrzeżenie: (0%)
-----


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.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 31.07.2025 - 06:30