Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

PHP coding "global"

  • 16-11-2005 03:17PM
    #1
    Registered Users, Registered Users 2 Posts: 673 ✭✭✭


    Hey,

    I'm learning PHP from a book at the moment and am stuck with this bit of code:

    //create function to get lead actor
    function get_leadactor($lead_actor) {
    global $actorname;
    $query2="SELECT people_fullname
    FROM people
    WHERE people.people_id = $lead_actor";
    $results=mysql_query($query2) or
    die(mysql error());
    $rows=mysql_fetch_array($results);
    extract ($rows);
    $actorname=$people_fullname;
    }


    I know that you are creating a function called "get_leadactor" and that it value will be stored in the variable "$lead_actor". What does "global $actorname;" do on the second line though?????

    I've been doing searched for "global" on the internet but i just keep on getting the same info about turning regictered_globals on/off in the php.ini file, but nothing telling me what this line of code is doing.

    Thanks for your help!!


Comments

  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    basically it is setting a global variable called $actorname

    And this $actorname get its value from $people_fullname


  • Registered Users, Registered Users 2 Posts: 2,207 ✭✭✭Serbian


    Global is setting the scope of the variable. You can read more about Variable Scope in the PHP Manual.


  • Registered Users, Registered Users 2 Posts: 673 ✭✭✭Bananna man


    Thanks :) back on track now.


Advertisement