Results 1 to 2 of 2

Thread: Getting variables from functions

  1. #1
    Join Date
    May 2010

    Question Getting variables from functions


    I am still trying fully grasp functions in php. I wrote a script that picks a random number between 1 and whatever number is entered when calling the function. I can echo the number it creates in the its function and then I call it to get the number echoed. I am trying to randomly display an image from a folder. But I can not call the variable and its really weighing me down because I want get the images size with getimagesize. I have tried global but its not working. Any help would be great.

    Thanks so much

    Here is what I have and tried commented out:
    PHP Code:
    function rand_uni($high){


    $rand_num_out="000" $num_to_convert ;    
    }else if(
    $rand_num_out="00" $num_to_convert ;    
    }else if(
    $rand_num_out="0" $num_to_convert ;    


    //global $rand_num_out;

    //which is called in //

    function obj(){
    $obj_height "100";
    $obj_width "150";

    $obj_directory "_img/_objects/";
    if (
    glob("$obj_directory*.gif") != false)
    $obj_filecount count(glob("$obj_directory*.gif")); 

    //global $rand_num_out;

                               //How I am Calling it now, wish I could just call the variable//
    echo"<img src=\"" $obj_directory;

    "no objects found :(";}

    Last edited by Savour; 12-03-2010 at 09:47 PM. Reason: clarification

  2. #2
    Join Date
    Aug 2004
    Generally, you want to return the value of interest from the function.
    PHP Code:
    // a stupid example function
    function foo($value)
    $value 2;

    foo(3); // outputs "6" 
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

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