1 Replies - 400 Views - Last Post: 21 March 2013 - 01:44 PM Rate Topic: -----

#1 rooster_bob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-March 13

Foreach Question

Posted 21 March 2013 - 01:44 PM

Hello, I have to print out an error message if the type of frog is not in the array. I have my array with my types of frogs:

$frogs = array('Tree Frog' => 'Tree Frog', 'Arrow Frog' => 'Arrow Frog', 'Dart Frog' => 'Dart Frog', 'Toad' => 'Toad');

foreach ($frogs as $key => $value) {
 if (! in_array($value, $shows) )  {
    $form_errors[] = 'Please choose a valid type of frog.';
  }
}



This code is just used to check to make sure that somebody is not getting into my form in the back end using something like Firebug to mess around with stuff. I need it to print the error out ONE TIME if the user tampers with the backend. It needs to check in the array and see if there it is there. I have all of the code printing out nicely with the exception of this. Right now it's not doing anything in my code. I just need to know how to loop it.

Thank you!

This post has been edited by JackOfAllTrades: 21 March 2013 - 01:44 PM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Foreach Question

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,548
  • Joined: 23-August 08

Re: Foreach Question

Posted 21 March 2013 - 01:44 PM

Look into using the break; statement.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1