SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IF equal to many things?!?

    How can I make this work...

    PHP Code:
    if($page == ('calendar','creatematch','createseason','report','categories')){
       echo 
    'Something here';
    } else {
       echo 
    'Something else';

    Is there a solution for this?

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One way:
    PHP Code:
    switch ($page) {
        case 
    'calendar':
        case 
    'creatematch':
        case 
    'createseason':
        case 
    'report':
        case 
    'categories':
            echo 
    'Something here';
            break;
        default:
            echo 
    'Something else'

    another way:

    PHP Code:
    if($page=='calendar'||$page=='creatematch'||$page=='createseason'||$page=='report'||$page=='categories'){ 
       echo 
    'Something here'
    } else { 
       echo 
    'Something else'

    another way:

    PHP Code:
    $valid = array('calendar','creatematch','createseason','report','categories');

    if(
    in_array($page,$valid)){ 
       echo 
    'Something here'
    } else { 
       echo 
    'Something else'


  3. #3
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    You could use in_array, for example:

    PHP Code:
    if (in_array($page, array('calendar','creatematch','createseason','report','categories'))) {
        echo 
    'Something here';
    } else {
        echo 
    'Something else';

    Salathe
    Software Developer and PHP Manual Author.

  4. #4
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in_array did the job... Thanks :-)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •