Any way to break if statement in PHP?

Posted by Usman on Stack Overflow See other posts from Stack Overflow or by Usman
Published on 2011-09-19T09:29:19Z Indexed on 2011/11/15 1:51 UTC
Read the original article Hit count: 142

Filed under:

Is there any command in PHP to stop executing the current or parent if statement, same as break or break(1) for switch/loop. For example

$arr=array('a','b');
foreach($arr as $val)
{
  break;
  echo "test";
}

echo "finish";

in the above code PHP will not do echo "test"; and will go to echo "finish";

I need this for if

$a="test";
if("test"==$a)
{
  break;
  echo "yes"; // I don't want this line or lines after to be executed, without using another if
}
echo "finish";

I want to break the if statement above and stop executing echo "yes"; or such codes which are no longer necessary to be executed, there may be or may not be an additional condition, is there way to do this?

© Stack Overflow or respective owner

Related posts about php