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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Array Values in function

    I think I need to rethink one of my scripts, and turn it into more of a common function that can be used in various places. In doing so, I was wondering if its possibly to use an array to include all the necessary variables needed.

    I was thinking for example that I could query a row from a table, with all its values in an array.

    Then to use the array values when calling the function. An example of something like below. Would the array values have to return the same fields name all the time? Or is something like this not possible?

    PHP Code:
    $values = array('player','color','gid','gname');

    function 
    game_log($values)
    {
        
    $player $values['player'];
        
        
    blahblahblahrest of function


  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by ptmuldoon View Post
    Would the array values have to return the same fields name all the time?
    Not necessarily, but you would probably want them to. If you selected the fields from the database the array would look more like this, though:
    PHP Code:
    $array = array('player' => 'ptmuldoon''color' => 'blue''gid' => 1'gname' => 'ptmuldoon'); 


  •  

    Posting Permissions

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