Jump to content

case and break


irkevin

Recommended Posts

A switch is a way to handle/execute code based on certain conditions. Example...

 

 

<?php

  $content = $_GET['content'];

  switch ($content) {

    case 'members':
      //Load members only area. 
    break;

    case 'login':
      //Load login area. 
    break;

    default:
       // Load main area.
    break;

  }

?>

 

In the above example the switch checks the $content variable and depending on what it's value is, will load the appropriate content.

 

There are tons of example online on using classes in PHP. I definitely recommend looking into it and taking an OOP approach to writing code (Object Oriented Programming).

Link to comment
https://forums.phpfreaks.com/topic/73576-case-and-break/#findComment-371216
Share on other sites

Case is used in a switch statement. You can read more about that here

www.php.net/switch

 

Break is used to stop the execution of a loop

http://us2.php.net/break

 

Classes are a huge topic. You can learn about them here

http://us.php.net/class

Or there are plenty of tutorials on the internet.

Link to comment
https://forums.phpfreaks.com/topic/73576-case-and-break/#findComment-371218
Share on other sites

Oh thanks for the quick response. . and what about global function.. I think it's something like that

 

function whatever(){

global $first;

echo $first;

}

 

what does the global means there?

 

P.S: sorry if i'm not using google for this.. i really want to get answers from people in this forum. this will give me some idead how it really works

 

 

Link to comment
https://forums.phpfreaks.com/topic/73576-case-and-break/#findComment-371221
Share on other sites

global will make the variable in scope for the function.

 

If you did this

 

<?php

$first = "blah";

function whatever(){
   echo $first;
}

?>

 

The $first var wouldn't be echoed in the function because it is out of scope. So you would have to do what you did in your example.

 

http://us.php.net/global

Link to comment
https://forums.phpfreaks.com/topic/73576-case-and-break/#findComment-371224
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.