Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Zamiana wartosci i wyswietlenie tylko jednej
AndyPSV
post
Post #1





Grupa: Zarejestrowani
Postów: 393
Pomógł: 5
Dołączył: 6.02.2003
Skąd: The.Luciferian.Doctrine.p
df

Ostrzeżenie: (30%)
XX---


Jak zrobic by jesli _from jest rowne _to badz _to jest rowne _from --- by wybral tylko ten \z ID wyzszym?

  1. 0 =>
  2. 'id' => '8',
  3. '_from' => '2',
  4. '_to' => '1',
  5. 'date' => '2018-10-15 15:51:07',
  6. 'message' => 'ccccccxxxxx',
  7. 'read' => '0',
  8. 'feedback' => '0',
  9. 'cnt' => '3',
  10. ),
  11. 1 =>
  12. 'id' => '6',
  13. '_from' => '1',
  14. '_to' => '2',
  15. 'date' => '2018-10-15 15:47:01',
  16. 'message' => 'zzzzzzz1',
  17. 'read' => '1',
  18. 'feedback' => '0',
  19. 'cnt' => '1',
  20. ),*/

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
AndyPSV
post
Post #2





Grupa: Zarejestrowani
Postów: 393
Pomógł: 5
Dołączył: 6.02.2003
Skąd: The.Luciferian.Doctrine.p
df

Ostrzeżenie: (30%)
XX---


  1. $newArray = '';
  2. foreach ($pm as $item) {
  3. $uniqueRecordKey = $item['_from'].'-'.$item['_to'];
  4. $oppositeRecordKey = $item['_to'].'-'.$item['_from'];
  5.  
  6. //If exists record from the opposite and new ID is greater than previous put
  7. if (isset($newArray[$oppositeRecordKey])) {
  8. $oppositeRecordKey[$uniqueRecordKey] = $item;
  9. continue; //Do not append to the end
  10. }
  11.  
  12. $newArray[$uniqueRecordKey] = $item;
  13. }
  14.  
  15. $pm = $newArray;
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: 12.10.2025 - 23:52