LuciaNNN. Posted August 7, 2019 Report Share Posted August 7, 2019 Salut, am si eu o problema cu funcția array_filtrer, mai exact am într-un array spații libere, ex: Array ( [0] => "valoare1" [1] => [2] => " valoare2" [3] => ); Cand folosesc funcția array_filtrer, imi elimină doar ultimul key (in exemplul de mai sus, 3) key-urile din mijloc rămânând acolo (precum in exemplul de mai sus, key-ul 1), se poate crea o rezolvare pentru acesta astfel încât să imi elimine orice key cu acel spațiu null? Array-ul l-am obținut dintr-un fisier .txt dupa ce i-am rescris unele părți din acesta, iar la sfârșit mi-a iesit o astfel de problemă... Quote Filme: Click. Contact: Steam Link to comment Share on other sites More sharing options...
Moderators Courage Posted August 8, 2019 Moderators Report Share Posted August 8, 2019 $arr = array_filter($arr, function($var){ return empty($var); }); Merge ok cu asta? 1 Quote Link to comment Share on other sites More sharing options...
LuciaNNN. Posted August 8, 2019 Author Report Share Posted August 8, 2019 11 hours ago, Courage said: $arr = array_filter($arr, function($var){ return empty($var); }); Merge ok cu asta? Nu, mi-a returnat ultimul key (unul null) si pe restul le-a eliminat :)) returnarea se va face daca este diferit de empty :) P.S corect trebuia: $arr = array_filter($arr, function($var){ return !empty($var); }); Insa nu a functionat... Quote Filme: Click. Contact: Steam Link to comment Share on other sites More sharing options...
+Sn!k3rs Posted August 8, 2019 Report Share Posted August 8, 2019 $rezolvare = [ 0 => 'val1', 1 => false, 2 => "val2", 3 => null, 4 => '', 5 => '0', 6 => 0, 7 => '', ]; print_r(array_filter($rezolvare)); Quote 1 Quote Link to comment Share on other sites More sharing options...
LuciaNNN. Posted August 8, 2019 Author Report Share Posted August 8, 2019 27 minutes ago, Sn!k3rs said: $rezolvare = [ 0 => 'val1', 1 => false, 2 => "val2", 3 => null, 4 => '', 5 => '0', 6 => 0, 7 => '', ]; print_r(array_filter($rezolvare)); Doar ce am spus ca in filtrare imi elimina doar ultimul key, anyway, am rezolvat. Problema nu era la array ci la modul cum am filtrat eu datele inainte de a ajunge in array. Dupa ce am verificat cu var_dump, am aflat ca nu erau nulle si ca ele contineau un string de 10 caractere (taguri html ce nu puteau fi afisate pe pagina web..)... Quote Filme: Click. Contact: Steam Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.