php - Converting Block of code Into Function -


i have few lines of code:

        $array_to_filter // array unfiltered     array_filter($array_to_filter, function($v){return array_filter($v) == array();});     $c = function($v){     return array_filter($v) != array();     };     $filtered_array = array_filter($airbnb, $c);       print_r($filtered_array); // filtered array! 

now using piece of code alot in code , don't want repeat every time! have tried this:

    function filter_array ($tofilter, $filtered) {      array_filter($tofilter, function($v){return array_filter($v) == array();});     $c = function($v){     return array_filter($v) != array();     };     $filtered = array_filter($filtered, $c);      return $filtered; } 

and calling this: filter_array($array_to_filter, $filtered_array);

without luck.. doing wrong?

the array want filter:

    [0] => array     (         [res_id] => 2927135         [confirmation] =>  qbmnma         [airbnb_agency_income] =>  €497         [airbnb_income] =>  €516          [airbnb_fees] =>  -€19          [airbnb_per_night] =>  €129     )  [1] => array     (         [res_id] =>          [confirmation] =>          [airbnb_agency_income] =>          [airbnb_income] =>          [airbnb_fees] =>          [airbnb_per_night] =>      ) 

the result via block of code:

 [0] => array     (         [res_id] => 2927135         [confirmation] =>  qbmnma         [airbnb_agency_income] =>  €497         [airbnb_income] =>  €516          [airbnb_fees] =>  -€19          [airbnb_per_night] =>  €129     ) 

the result via function:

<p>severity: warning</p> <p>message:  array_filter() expects parameter 1 array, null given</p> <p>filename: controllers/welcome.php</p> <p>line number: 456</p> 

i have associative array of arrays empty! inside example [res_id] => want rid of whole array not key. that's – valery 5 mins ago

function filter_array ($to_filter) {     foreach ($to_filter $index => $child_array)     {         if (!array_filter($child_array)) {             // keys empty.             unset($to_filter[$index]);         }     }  return $to_filter; }  $filtered_array = filter_array($array_to_filter); 

would work?


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -