PHP remove entry if array value equals to 0 -


this when print_r array. it's multi-dimensional array contains following values.

    [7] => array     (         [0] => 1         [1] => 34         [2] => 181         [3] => 50     )        [9] => array     (         [0] => 1         [1] => 2         [2] => 1         [3] => 47     )     [2] => array     (         [0] => 20         [1] => 0         [2] => 1621         [3] => 45     )    [3] => array     (         [0] => 120         [1] => 0         [2] => 121         [3] => 45     ) 

i remove entries in key [1] equals 0. after doing modifications, final array should

    [7] => array     (         [0] => 1         [1] => 34         [2] => 181         [3] => 50     )    [9] => array     (         [0] => 1         [1] => 2         [2] => 1         [3] => 47     ) 

any ideas ?

foreach rescue:

foreach($arr $key => $entry) {     if(isset($entry[1]) && $entry[1] === 0) {         unset($arr[$key]);     } } 

and array_filter example:

$arr = array_filter($arr, function($entry) {     return $entry[1] !== 0; }); 

(assumes @ least php 5.3, though can around creating named function , passing second parameter array_filter)


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -