Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] Zamiana wartosci i wyswietlenie tylko jednej
AndyPSV
post 15.10.2018, 15:21:28
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
werdan
post 16.10.2018, 20:10:02
Post #2





Grupa: Zarejestrowani
Postów: 354
Pomógł: 100
Dołączył: 14.11.2013
Skąd: Płock

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


Poniżej działający przykład:

  1.  
  2. <?php
  3.  
  4.  
  5. $a = [
  6. [
  7. 'id' => '8',
  8. '_from' => '2',
  9. '_to' => '2',
  10. 'date' => '2018-10-15 15:51:07',
  11. 'message' => 'ccccccxxxxx',
  12. 'read' => '0',
  13. 'feedback' => '0',
  14. 'cnt' => '3',
  15. ],
  16. [
  17. 'id' => '6',
  18. '_from' => '2',
  19. '_to' => '2',
  20. 'date' => '2018-10-15 15:47:01',
  21. 'message' => 'zzzzzzz1',
  22. 'read' => '1',
  23. 'feedback' => '0',
  24. 'cnt' => '1',
  25. ]
  26. ];
  27.  
  28.  
  29. $b = array_filter($a, function($row){
  30. return ($row['_from'] == $row['_to']);
  31. });
  32.  
  33. print_r($b);
  34.  
  35. function sort_arr($item_1, $item_2)
  36. {
  37. return $item_2['time'] - $item_1['time'];
  38. }
  39.  
  40. usort($b, function($x, $y){
  41.  
  42. return $y['id'] - $x['id'];
  43. });
  44.  
  45. $max = null;
  46. if(count($b)){
  47. $max = reset($b);
  48. }
  49.  
  50. print_r($max);
  51.  
  52.  
Go to the top of the page
+Quote Post
AndyPSV
post 17.10.2018, 12:10:23
Post #3





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

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


Nie dziala mi ten przyklad

tu jest przyklad danych z $pm;

  1. 0 =>
  2. 'id' => '8',
  3. '_from' => '2',
  4. '_to' => '1',
  5. 'date' => '2018-10-15 15:51:07',
  6. 'message' => 'ccccccxxxxx',
  7. 'read' => '1',
  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. ),
  21. 2 =>
  22. 'id' => '4',
  23. '_from' => '3',
  24. '_to' => '1',
  25. 'date' => '2018-10-15 15:20:47',
  26. 'message' => 'aaaaaaaaaa1e2642d888b14f0df948682041e48fa31391081110-480-272-301....flv
  27. 1e2642d888b14f0df948682041e48fa31391081110-480-272-301-h264.flv play
  28. energy 2000 stare ale nadal jare-).mp3
  29. lil peep - benz truck (prod. smokeasac).mp3
  30. NAJWAZNIEJSZA,+websites.2013-05-31vPACK-ALL.rar
  31. httpd-WEBPAGES,2014-11-24v1-PASS.PROTECTED.rar
  32. Gang Albanii-Narkotykowy odlot (Instrumental).mp3
  33. Gang Albanii-Blachary (Instrumental).mp3
  34. 1e2642d888b14f0df948682041e48fa31391081110-480-272-301....flv
  35. 1e2642d888b14f0df948682041e48fa31391081110-480-272-301-h264.flv play
  36. energy 2000 stare ale nadal jare-).mp3
  37. lil peep - benz truck (prod. smokeasac).mp3
  38. NAJWAZNIEJSZA,+websites.2013-05-31vPACK-ALL.rar
  39. httpd-WEBPAGES,2014-11-24v1-PASS.PROTECTED.rar
  40. Gang Albanii-Narkotykowy odlot (Instrumental).mp3
  41. Gang Albanii-Blachary (Instrumental).mp3
  42. 1e2642d888b14f0df948682041e48fa31391081110-480-272-301....flv
  43. 1e2642d888b14f0df948682041e48fa31391081110-480-272-301-h264.flv play
  44. energy 2000 stare ale nadal jare-).mp3
  45. lil peep - benz truck (prod. smokeasac).mp3
  46. NAJWAZNIEJSZA,+websites.2013-05-31vPACK-ALL.rar
  47. httpd-WEBPAGES,2014-11-24v1-PASS.PROTECTED.rar
  48. Gang Albanii-Narkotykowy odlot (Instrumental).mp3
  49. Gang Albanii-Blachary (Instrumental).mp3
  50. 1e2642d888b14f0df948682041e48fa31391081110-480-272-301....flv
  51. 1e2642d888b14f0df948682041e48fa31391081110-480-272-301-h264.flv play
  52. energy 2000 stare ale nadal jare-).mp3
  53. lil peep - benz truck (prod. smokeasac).mp3
  54. NAJWAZNIEJSZA,+websites.2013-05-31vPACK-ALL.rar
  55. httpd-WEBPAGES,2014-11-24v1-PASS.PROTECTED.rar
  56. Gang Albanii-Narkotykowy odlot (Instrumental).mp3
  57. Gang Albanii-Blachary (Instrumental).mp3',
  58. 'read' => '1',
  59. 'feedback' => '0',
  60. 'cnt' => 7,
  61. ),
  62. )
Go to the top of the page
+Quote Post
AndyPSV
post 17.10.2018, 12:29:20
Post #4





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

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


Chodzi o to by OUTPUT byl taki:

  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. ),


z wysszym ID jeden klucz co jest taki sam _from jak _to
Go to the top of the page
+Quote Post
AndyPSV
post 19.10.2018, 12:36:56
Post #5





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

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: 16.04.2024 - 10:33