Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Wyciąganie danych z tablic
czvpka
post 24.02.2017, 15:19:48
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 1
Dołączył: 22.02.2017

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


Witam. Mam taką oto tablicę $users:
Kod
array(3) {
  ["success"]=>
  bool(true)
  ["errors"]=>
  NULL
  ["data"]=>
  array(5) {
    [0]=>
    array(5) {
      ["clid"]=>
      string(1) "2"
      ["cid"]=>
      string(3) "380"
      ["client_database_id"]=>
      string(1) "1"
      ["client_nickname"]=>
      string(35) "serveradmin from 94.254.153.85:9253"
      ["client_type"]=>
      string(1) "1"
    }
    [1]=>
    array(5) {
      ["clid"]=>
      string(1) "6"
      ["cid"]=>
      string(3) "380"
      ["client_database_id"]=>
      string(3) "275"
      ["client_nickname"]=>
      string(22) "MusicBot ☆ HiveSpeak"
      ["client_type"]=>
      string(1) "0"
    }
    [2]=>
    array(5) {
      ["clid"]=>
      string(2) "16"
      ["cid"]=>
      string(3) "380"
      ["client_database_id"]=>
      string(1) "1"
      ["client_nickname"]=>
      string(21) "PokeBot ☆ HiveSpeak"
      ["client_type"]=>
      string(1) "1"
    }
    [3]=>
    array(5) {
      ["clid"]=>
      string(2) "19"
      ["cid"]=>
      string(3) "380"
      ["client_database_id"]=>
      string(1) "1"
      ["client_nickname"]=>
      string(26) "Aktualizator ☆ HiveSpeak"
      ["client_type"]=>
      string(1) "1"
    }
    [4]=>
    array(5) {
      ["clid"]=>
      string(2) "20"
      ["cid"]=>
      string(3) "380"
      ["client_database_id"]=>
      string(1) "1"
      ["client_nickname"]=>
      string(21) "TimeBot ☆ HiveSpeak"
      ["client_type"]=>
      string(1) "1"
    }
  }
}

I chciałbym z tego wyciągnąć każdą wartość "clid". Wynalazłem, że aby wyciągnąć wszystkich użytkowników, muszę użyć $users['data'], lecz co muszę zrobić dalej, aby wyciągnąć wszystkie "clid"? Proszę o pomoc. Pozdrawiam smile.gif
Go to the top of the page
+Quote Post
viking
post 24.02.2017, 15:23:42
Post #2





Grupa: Zarejestrowani
Postów: 6 378
Pomógł: 1116
Dołączył: 30.08.2006

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


Zastosować pętlę na tablicy data.


--------------------
Go to the top of the page
+Quote Post
czvpka
post 24.02.2017, 15:31:34
Post #3





Grupa: Zarejestrowani
Postów: 8
Pomógł: 1
Dołączył: 22.02.2017

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


  1. #while(1) {
  2. foreach($channels as $channel) {
  3. $users = $tsAdmin->channelClientList($channel, "-clid");
  4. foreach($users as $user) { <--- tutaj błąd
  5. foreach($user as $key=>$value) {
  6. echo $value['clid'];
  7. }
  8. }
  9. }
  10. sleep(15);
  11. #}

Tutaj mi wywala dwa błędy Invalid argument supplied in foreach() na linii 16 czyli tam, gdzie zaznaczyłem w kodzie. Ktoś coś?
Go to the top of the page
+Quote Post
viking
post 24.02.2017, 15:32:52
Post #4





Grupa: Zarejestrowani
Postów: 6 378
Pomógł: 1116
Dołączył: 30.08.2006

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


var_dump($users) po linii 3 (według numeracji posta wyżej).


--------------------
Go to the top of the page
+Quote Post
ohm
post 24.02.2017, 15:33:15
Post #5





Grupa: Zarejestrowani
Postów: 623
Pomógł: 144
Dołączył: 22.12.2010

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


sprobuj array_column($array['data'], "clid")

Ten post edytował ohm 24.02.2017, 15:38:27
Go to the top of the page
+Quote Post
czvpka
post 24.02.2017, 15:36:18
Post #6





Grupa: Zarejestrowani
Postów: 8
Pomógł: 1
Dołączył: 22.02.2017

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


@viking
Kod
array(3) {
  ["success"]=>
  bool(true)
  ["errors"]=>
  NULL
  ["data"]=>
  array(5) {
    [0]=>
    array(5) {
      ["clid"]=>
      string(1) "2"
      ["cid"]=>
      string(3) "380"
      ["client_database_id"]=>
      string(1) "1"
      ["client_nickname"]=>
      string(35) "serveradmin from 94.254.153.85:9253"
      ["client_type"]=>
      string(1) "1"
    }
    [1]=>
    array(5) {
      ["clid"]=>
      string(1) "5"
      ["cid"]=>
      string(3) "380"
      ["client_database_id"]=>
      string(1) "1"
      ["client_nickname"]=>
      string(21) "PokeBot ☆ HiveSpeak"
      ["client_type"]=>
      string(1) "1"
    }
    [2]=>
    array(5) {
      ["clid"]=>
      string(1) "6"
      ["cid"]=>
      string(3) "380"
      ["client_database_id"]=>
      string(3) "275"
      ["client_nickname"]=>
      string(22) "MusicBot ☆ HiveSpeak"
      ["client_type"]=>
      string(1) "0"
    }
    [3]=>
    array(5) {
      ["clid"]=>
      string(2) "19"
      ["cid"]=>
      string(3) "380"
      ["client_database_id"]=>
      string(1) "1"
      ["client_nickname"]=>
      string(26) "Aktualizator ☆ HiveSpeak"
      ["client_type"]=>
      string(1) "1"
    }
    [4]=>
    array(5) {
      ["clid"]=>
      string(2) "20"
      ["cid"]=>
      string(3) "380"
      ["client_database_id"]=>
      string(1) "1"
      ["client_nickname"]=>
      string(21) "TimeBot ☆ HiveSpeak"
      ["client_type"]=>
      string(1) "1"
    }
  }
}
Go to the top of the page
+Quote Post
viking
post 24.02.2017, 15:40:31
Post #7





Grupa: Zarejestrowani
Postów: 6 378
Pomógł: 1116
Dołączył: 30.08.2006

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


foreach($users['data'] as $user)

To są kompletne podstawy tablic.


--------------------
Go to the top of the page
+Quote Post
czvpka
post 24.02.2017, 15:43:40
Post #8





Grupa: Zarejestrowani
Postów: 8
Pomógł: 1
Dołączył: 22.02.2017

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


Kompletne podstawy, lecz jednak miałem z tym problem :/ Długo nie korzystałem z PHP smile.gif W każdym czy innym razie dzięki za pomoc i poświęcony czas, lecą plusy (pomógł) i temat do zamknięcia smile.gif
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: 15.07.2025 - 13:35