Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Funkcja usuwająca puste elementy tablicy?
MacDada
post
Post #1





Grupa: Zarejestrowani
Postów: 47
Pomógł: 1
Dołączył: 24.06.2010
Skąd: Sopot

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


Teraz robię to tak:

  1. $tablicaZPustymiElementami = Array('', 'elem1', 'elem2', '', 'elem3');
  2. $tablicaBezPustychElementow = Array();
  3.  
  4. foreach ($tablicaZPustymiElementami as $element)
  5. if (!empty($element))
  6. array_push($tablicaBezPustychElementow, $element);
  7.  
  8. unset($tablicaZPustymiElementami);


Może jest do tego jakaś dedykowana funkcja?

Ten post edytował MacDada 8.08.2010, 13:20:08
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




A po co dodatkowa tablica?
  1. $tablicaZPustymiElementami = Array('', 'elem1', 'elem2', '', 'elem3');
  2.  
  3. foreach ($tablicaZPustymiElementami as $key => $element)
  4. if (empty($element))
  5. unset($tablicaZPustymiElementami[$key]);


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
skarabe.pl
post
Post #3





Grupa: Zarejestrowani
Postów: 142
Pomógł: 49
Dołączył: 29.07.2010

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


Jest funkcja - array_filter
  1. $tablica = array_filter($tablica);
Go to the top of the page
+Quote Post
MacDada
post
Post #4





Grupa: Zarejestrowani
Postów: 47
Pomógł: 1
Dołączył: 24.06.2010
Skąd: Sopot

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


Cytat(skarabe.pl @ 8.08.2010, 14:37:35 ) *
Dzięki
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 Aktualny czas: 21.08.2025 - 16:48