Problems with IF Statement

  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

So, I'm running a loop to loop through requirements. I'm wanting to write an IF statement that says if it gets to the end of the loop and there wasn't a requirement with a ShortDescription = Check School Expiration Date, then do something else. I know that I can't do this:

Code: [ Select ]
foreach ($req as $dx=>$requirement) {
if (!isset($requirement->ShortDescription=='Check School Expiration Date')) {
echo 'Not present<br>';
}
}
  1. foreach ($req as $dx=>$requirement) {
  2. if (!isset($requirement->ShortDescription=='Check School Expiration Date')) {
  3. echo 'Not present<br>';
  4. }
  5. }

but this should give you an idea of what I'm looking to do. I can't think for the life of me, how to do this. Any help would be greatly appreciated!!!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 449

Post 3+ Months Ago

Is it an array of requirements?

like
PHP Code: [ Select ]
 
$req = array(
        (object) array("ShortDescription" => 'Class thats at the end of the hall'),
        (object) array("ShortDescription" => 'A room with a moose.'),
        (object) array("ShortDescription" => 'Check School Expiration Date')
        );
 
 
  1.  
  2. $req = array(
  3.         (object) array("ShortDescription" => 'Class thats at the end of the hall'),
  4.         (object) array("ShortDescription" => 'A room with a moose.'),
  5.         (object) array("ShortDescription" => 'Check School Expiration Date')
  6.         );
  7.  
  8.  


If not could you give us an idea of what $req is .... var_dump($req);
  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

Yes, it's in an array of requirements.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 449

Post 3+ Months Ago

This is quick and dirty and i can most likely come up with a better solution if you var_dump() the req

but dose something like this work for you?
PHP Code: [ Select ]
$req = array(
        (object) array("ShortDescription" => 'Class thats at the end of the hall'),
        (object) array("ShortDescription" => 'A room with a moose.'),
        (object) array("ShortDescription" => 'Check School Expiration Date')
        );
 
$reqirements_met = array("check_school_expiration_date" => false);
 
foreach ($req as $dx => $requirement) {
   if ($requirement->ShortDescription == 'Check School Expiration Date') {
      $reqirements_met["check_school_expiration_date"] = true;
   }
}
 
if($reqirements_met["check_school_expiration_date"]) {
   echo 'requirement found';
} else {
   echo 'requirement not found';
}
 
  1. $req = array(
  2.         (object) array("ShortDescription" => 'Class thats at the end of the hall'),
  3.         (object) array("ShortDescription" => 'A room with a moose.'),
  4.         (object) array("ShortDescription" => 'Check School Expiration Date')
  5.         );
  6.  
  7. $reqirements_met = array("check_school_expiration_date" => false);
  8.  
  9. foreach ($req as $dx => $requirement) {
  10.    if ($requirement->ShortDescription == 'Check School Expiration Date') {
  11.       $reqirements_met["check_school_expiration_date"] = true;
  12.    }
  13. }
  14.  
  15. if($reqirements_met["check_school_expiration_date"]) {
  16.    echo 'requirement found';
  17. } else {
  18.    echo 'requirement not found';
  19. }
  20.  
  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

That worked perfectly! Thank you so much!!!
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 449

Post 3+ Months Ago

your welcome

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 128 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.