irkevin Posted October 17, 2007 Share Posted October 17, 2007 hi, sorry to bug you with this but can someone give me a brief explanation or code example of what case and break do in php? and what about classes? If it's a long explanation, then disgard this post! Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/73576-case-and-break/ Share on other sites More sharing options...
SammyGunnz Posted October 17, 2007 Share Posted October 17, 2007 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). Quote Link to comment https://forums.phpfreaks.com/topic/73576-case-and-break/#findComment-371216 Share on other sites More sharing options...
pocobueno1388 Posted October 17, 2007 Share Posted October 17, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73576-case-and-break/#findComment-371218 Share on other sites More sharing options...
irkevin Posted October 17, 2007 Author Share Posted October 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/73576-case-and-break/#findComment-371221 Share on other sites More sharing options...
pocobueno1388 Posted October 17, 2007 Share Posted October 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/73576-case-and-break/#findComment-371224 Share on other sites More sharing options...
irkevin Posted October 17, 2007 Author Share Posted October 17, 2007 thnx a lot for your replies.. i appreciate your time Quote Link to comment https://forums.phpfreaks.com/topic/73576-case-and-break/#findComment-371246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.