SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Define var in current scope

    Sorry for the lousy summary heading, but what I need is pretty simple to explain with an example. Imagine you have a hash, like so:

    PHP Code:
    $myhash["one"] = 1;
    $myhash["two"] = 2;
    $myhash["three"] = 3
    Now, I'd like to define the keys as actual variables in the current scope - but NOT as globals. So in other words, I want to get this out of it:

    PHP Code:
    $one 1;
    $two 2;
    $three 3
    I thought I could just use $$ but I can't seem to figure out the syntax for actually creating the vars...

    Any idea? Thanks!!

    - Ben
    A.P.

    generatedata.com - free JS/PHP/MySQL random test data generator.
    Form Tools - free PHP/MySQL form processor.

  2. #2
    SitePoint Member JAY6390's Avatar
    Join Date
    Oct 2009
    Location
    UK
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Boy I love this site.

    Thanks, Jay - perfect.
    A.P.

    generatedata.com - free JS/PHP/MySQL random test data generator.
    Form Tools - free PHP/MySQL form processor.

  4. #4
    SitePoint Member JAY6390's Avatar
    Join Date
    Oct 2009
    Location
    UK
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem. You could also do it the hard way
    PHP Code:
    foreach($myhash as $k => $v) $$k $v


Bookmarks

Posting Permissions

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