arrays - PHP : foreach - Return issue (after first occurence) -


issue resolved , here solution :

function finaltimetestt()     {         $timecheckarray = maketimecheck();          $tbool = true;          if(count($timecheckarray) >0)         {             foreach($timecheckarray $tca)             {                 if($tca['value'] != "true")                 {                     $tbool = false;                     return array($tbool , $tca['courseid'] , $tca['day']);                     break;                 }                 else                 {                     // nothing                 }             }         }         else         {             return array($tbool);         }          return array($tbool);     } 

i'm having small problem code , driving me crazy :

i want go through multi-dimensional array , if 1 of values false , should out of loop , return value - break; doesn't seem working , returning true tho there 1 occurence of "false"

$timecheckarray gives :

array ( [0] => array ( [courseid] => comp248 [day] => monday [value] => true ) [1] => array ( [courseid] => comp248 [day] => monday [value] => true ) [2] => array ( [courseid] => comp345 [day] => monday [value] => false ) )

function finaltimetestt()     {         $timecheckarray = maketimecheck();          if(count($timecheckarray) >0)         {             foreach($timecheckarray $tca)             {                 if($tca['value'] == "true")                 {                     return array(true);                 }                 else                 {                     return array(false , $tca['courseid'] , $tca['day']);                     break;                 }             }         }         else         {             return array(true);         }     } 

i'm using function :

$hhhbool = finaltimetestt();  if($hhhbool[0]) {   echo "true"; } else {   echo "false"; } 

it returning true , tho there value "false" in array above.

your finaltimetestt() returning array(true) because never gets past first element in $timecheckarray array - both branches of if statement in foreach loop return.

the first iteration looks @ array ( [courseid] => comp248 [day] => monday [value] => true ). value of value key true, $tca['value'] == "true" evaluates true, return array(true); executed, , function ends there. use of break after return statement suggests don't quite understand latter does.

i think want body of foreach loop this:

if ($tca['value'] != 'true') {     return array(false, $tca['courseid'], $tca['day']); } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -