Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Operacje na obiektach
miedzna
post
Post #1





Grupa: Zarejestrowani
Postów: 401
Pomógł: 1
Dołączył: 10.03.2004
Skąd: Warszawa

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


Hej, mam dane objektowe jak poniżej. Jak zmienić klucze
[0] => stdClass Object
[1] => stdClass Object
[2] => stdClass Object
[3] => stdClass Object
[4] => stdClass Object

na odpowiedniki z pozbioru, czyli
[id] => 3
[id] => 2
[id] => 2
[id] => 1
[id] => 1

czyli żeby było tak
[3] => stdClass Object
[2] => stdClass Object
[2] => stdClass Object
[1] => stdClass Object
[1] => stdClass Object

  1. (
  2. [0] => stdClass Object
  3. (
  4. [id] => 3
  5. [clientID] => 123
  6. )
  7.  
  8. [1] => stdClass Object
  9. (
  10. [id] => 2
  11. [clientID] => 456
  12. )
  13.  
  14. [2] => stdClass Object
  15. (
  16. [id] => 2
  17. [clientID] => 789
  18. )
  19.  
  20. [3] => stdClass Object
  21. (
  22. [id] => 1
  23. [clientID] => 1011
  24. )
  25.  
  26. [4] => stdClass Object
  27. (
  28. [id] => 1
  29. [clientID] => 1234
  30. )
  31. )
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
IAmBoskiM
post
Post #2





Grupa: Zarejestrowani
Postów: 72
Pomógł: 11
Dołączył: 8.05.2016

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


  1. $arr = array(); // nie chce mi sie kopiowac ani nic tresci tej tablicy, ale to jest ta 0 1 2 3 itd
  2. $arr2 = array(); // pusta tablica
  3. foreach ($arr as $value) {
  4. $arr2[$value->id][] = $value->clientID;
  5. }
  6. // I wtedy masz cos takiego w $arr2, jezeli sie nie myle:
  7. 1 => array(
  8. 0 => $clientid1,
  9. 1 => $clientid2),
  10. 2 => array(
  11. 0 => $clientid3,
  12. 1 => $clientid4),
  13. 3 => array(
  14. 0 => $clientid5)
  15. )
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 1.01.2026 - 03:55