Announcement

Collapse
No announcement yet.

function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • function

    i have this code which appears serval times throughout the script:

    PHP Code:

            
    if ( $esrb == 1$esrb "K-A";
            if ( 
    $esrb == 2$esrb "E";
            if ( 
    $esrb == 3$esrb "T";  // pretty much specify the ESRB ratings
            
    if ( $esrb == 4$esrb "M";
            if ( 
    $esrb == 5$esrb "Ao";
            if ( 
    $esrb == 6$esrb "RP";

            if ( 
    $genre == 1$genre "Action";
            if ( 
    $genre == 2$genre "Adventure";
            if ( 
    $genre == 3$genre "Fighting";
            if ( 
    $genre == 4$genre "Racing";            // specify the genre
            
    if ( $genre == 5$genre "Role Playing";
            if ( 
    $genre == 6$genre "Simulation";
            if ( 
    $genre == 7$genre "Sports";

            if ( 
    $sv == $sv "<b>S</b>";
            if ( 
    $sv == $sv "<b>V</b>";            //    specify the Snapshots/ Videos
            
    if ( $sv == $sv "<b>SV</b>";

            if ( 
    $color == "#ACDEAC" ) {
                
    $color "#83CD83";                        // set the alternating colors
            
    } elseif ($color "#83CD83") {
                
    $color "#ACDEAC";
            } 
    is there anyway I can put this into a function, and then call it everytime i need it?

    thanks

    Dimava
    NXSupport Admin

  • #2
    You sure can!

    Check out the manual, to see a good example.


    Lats...
    Lats...

    Comment


    • #3
      whats with all the if statements? use switch()

      Comment


      • #4
        why not make the ESRB and the genres and the SVs an array:

        PHP Code:
        $esrb_array = array(NULL"K-A""E""T""M""Ao""RP"); // "NULL" is there since you started at 1

        $genre_array = array(NULL"Action""Adventure""Fighting""Racing""Role Playing""Simulation""Sports");

        $sv_array = array(NULL"S""V""SV");

        function 
        get($type$num) {
            eval(
        "return \$${type}_array[\$num];");

        An example of a call would be

        PHP Code:
        get("genre"3); // returns "Fighting" 
        that should work

        Comment

        widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
        Working...
        X