www.webdeveloper.com
Results 1 to 2 of 2

Thread: simple function to change values of variables

  1. #1
    Join Date
    Oct 2007
    Posts
    126

    simple function to change values of variables

    Hi, I've got a load of variables which I want to change the values of. The variables are either empty / don't exist or contain the value 'YES'. If they contain the value 'YES' I want to leave them alone but if they are empty I want to give them the value of 'NO'.

    If i do this it works

    PHP Code:
    if (!$var){
    $var "NO";

    so I want to write a function that can process multiple variables, and if I do this it doesn't work:
    PHP Code:
    function yesno($value){
    if (!
    $value){
    $value "NO";
    }
    }

    yesno($var1);
    yesno($var2); 
    I'm assuming that using $value as a placeholder in the function suddenly gets confused with being a real variable when I put $value = "NO";

    I'm sure it's pretty simple, I just can't think what to search for as a work around.

    Thanks

  2. #2
    Join Date
    Jan 2005
    Posts
    592
    you need to return the new value.

    PHP Code:
    function yesno($value){
    if (!
    $value){
    return 
    "NO";
    }
    }

    $var1 yesno($var1);
    $var2 yesno($var2); 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles