Help with a simple switch statement
Posted
by revive
on Stack Overflow
See other posts from Stack Overflow
or by revive
Published on 2010-04-23T03:05:10Z
Indexed on
2010/04/23
3:13 UTC
Read the original article
Hit count: 467
I need to find the value of a variable and use it to add a class to a div, based on a switch statement.
For example, my variable is $link and if $link has google.com IN IT at all, I need $class to equal 'google', if $link as yahoo.com IN IT at all, $class then needs to equal 'yahoo'
So, I need something like this, but I'm not sure how/or if to use preg_match or something to check and see if the $link variable has the value we are looking for in it - see 'case' text below:
switch ($link) { case 'IF link has Google.com in it': $class = 'google'; break; case 'IF link has Yahoo.com in it': $class = 'yahoo'; break; default: # code... break; }
OR if there is a better way to do this, please let me know :D Thanks
© Stack Overflow or respective owner