Upgrade to Chess.com Premium!

How to determine if all values in an array equal 0, in PHP.

Hey, 

Very recently i was faced with the issue of determining whether all the elements within one column within an multi-dimensional associative array where equal to 0. After scouring various forums i was unable to find anything where this had been done before. So i thought i would mock up very quickly a function to do this for me. Which returns 1 if all values = 0, else returns 0.

Here is the code. 

 

function checkArray($array)

{

$x = 0;

for( $i = 0; $i < count($array); $i++)

{

if($array[$i]['estimatedTime'] == 0)

{

$x = 1;

}

else

{

break;

}

}

return $x;

}

 Any thoughts or suggestions, maybe there is a better way to do this. :) 

Joshua

 

Comments


  • 8 months ago

    uPokerBrat

    wow computer programming will be a challenge for me :P 

Back to Top

Post your reply: