Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.