1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

variable in function

Discussion in 'PHP' started by jonhyhar, May 16, 2011.

  1. #1
    Hello, I have a problem with variables, How can I fix the problem?

    the code:
    
    $variable = "100";
    $language = "english";
    
    function($number){
    $result = $number * 5;
    $result = "your language ".$language." and the variable is ".$result;
    return $result;
    }
    
    echo function($variable);
    
    Code (markup):

    p.s. I want to use like that function($number) , please don't say that "use this function($number, $lang)
     
    jonhyhar, May 16, 2011 IP
  2. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #2
    can u tell y u can't use a function($num,$lang); ?

    or may be something like this can work:
    
    $variable = "100";
    $language = "english";
    
    function($number){
    $result = $number * 5;
    $result. = " and the variable is ".$result;
    return $result;
    }
    
    echo  "your language ".$language.function($variable);
    
    PHP:
     
    arpit13, May 17, 2011 IP
  3. Mak3MyDay

    Mak3MyDay Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    here's the solution
    $variable = "100";
    $language = "english";
    
    function($number){
    global $language;
    $result = $number * 5;
    $result = "your language ".$language." and the variable is ".$result;
    return $result;
    }
    
    echo function($variable);
    Code (markup):
     
    Mak3MyDay, May 17, 2011 IP