Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with function, returning a variable

    Why doesn't this work? I can't get $pageTitle to echo out?

    PHP Code:
    function templateHeader($str) {
        
        
    $pageTitle $str;
        return 
    $pageTitle;
    }

    templateHeader('Dashboard');

    echo 
    $pageTitle

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,915
    Thanks
    15
    Thanked 227 Times in 227 Posts
    Kinda tricky, the first time you use it, that return. It only returns the data to a 'caller', which can be a variable.
    PHP Code:
    function templateHeader($str) {
        
        return 
    $str.'board';
    }

    $newstr=templateHeader('Dash');

    echo 
    $newstr
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Scope.
    There is no relationship between the $pageTitle within the function and the $pageTitle outside of it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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