Count the number of columns that do not contain a single zero element.

I managed to do it with strings, but how can I turn this with columns?

function GetCounterOfRowsWithoutZeroFromMatrix($matrix) { $counter = 0; for($i = 0; $i < count($matrix); $i++) { $hasZero = false; for ($j = 0; $j < count($matrix[$i]); $j++) if($matrix[$i][$j] == 0) { $hasZero = true; break; } if(!$hasZero) $counter++; } return $counter; } 

Now we need to come up with the GetCounterOfColumnsWithoutZeroFromMatrix method. Help)

    1 answer 1

    function GetCounterOfColumnsWithoutZeroFromMatrix($matrix){ $result = array(); foreach($matrix as $key=>$row){ $result = array_merge( array_keys( $row, 0, true ), $result); } return count(array_unique($result)); }
    function GetCounterOfColumnsWithoutZeroFromMatrix($matrix){ $result = array(); foreach($matrix as $key=>$row){ $result = array_merge( array_keys( $row, 0, true ), $result); } return count(array_unique($result)); }