Results 1 to 4 of 4

Thread: PHP question

  1. #1
    Administrator Bok's Avatar
    Join Date
    Oct 2003
    Location
    Wake Forest, North Carolina, United States
    Posts
    24,468
    Blog Entries
    13

    PHP question

    Is it possible to access the value of variable A by using the value of variable B as it's name ??

    For example, let's say I have 5 variables

    a_name,b_name,c_name,d_name,e_name

    I have an array defined as

    $myarray = array(a,b,c,d,e);

    foreach ($myarray as $myvalue) {

    $newname = $myvalue . "_name";

    # $newname will now = a_name for the first instance

    }

    is it possible to get the value of a_name by referencing $newname somehow ?

    I think I can do this in perl, but not sure about php ????



    Bok

  2. #2
    Stats Developer magnav0x's Avatar
    Join Date
    Mar 2002
    Location
    Dallas, TX
    Posts
    1,747
    Not sure if this is what you mean, but:


    PHP Code:
    $a_name 'test a';
    $b_name 'test b';
    $c_name 'test c';
    $d_name 'test d';
    $e_name 'test e';

    $myarray = array(a,b,c,d,e);

    foreach (
    $myarray as $myvalue) {
        
    $newname $myvalue "_name";
        echo $
    $newname."<br>";  //Will become echo $a_name, echo $b_name, etc...

    Warning this Post is Rated "M" for Mature

    -Contains Harsh Language
    -L337 HaX0r W3RD2!
    -Partial Nudity

    I haven't lost my mind; it's backed up on tape drive somewhere.

  3. #3
    Administrator Bok's Avatar
    Join Date
    Oct 2003
    Location
    Wake Forest, North Carolina, United States
    Posts
    24,468
    Blog Entries
    13
    That's exactly what I needed!!!

    Mag

    Bok

  4. #4
    Stats Developer magnav0x's Avatar
    Join Date
    Mar 2002
    Location
    Dallas, TX
    Posts
    1,747
    No problem, glad to help
    Warning this Post is Rated "M" for Mature

    -Contains Harsh Language
    -L337 HaX0r W3RD2!
    -Partial Nudity

    I haven't lost my mind; it's backed up on tape drive somewhere.

Posting Permissions

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