using variable within variable kinda thing - help needed

Discussion in 'PHP' started by blueparukia, Dec 25, 2007.

  1. #1
    OK, let's check this out hey?

    
    <?
    $link_1 = "1__Text1";
    $link_2 = "2__Text2";
    $link_3 = "3__Text3";
    $counter = 3;
    /*Invalid Code Here
    $value = explode(__,$link_.$counter);
    */
    ?>
    
    
    PHP:
    Now I want to explode it to separate
    number and text, however I want to use the variable for exploding() to be $link_number, and I have tried $link_.$counter, $link_{$counter} and more variations, including escaping the variable: $freshlink = "\$link_".$counter."";

    So a nudge in the right direction would prove incredibly helpful,

    Thanks,

    BP
     
    blueparukia, Dec 25, 2007 IP
    selling vcc likes this.
  2. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I guess this one will work... I'm not sure and I'm not on my lappy to test it now:

    ${"link_$counter"}
    PHP:
     
    selling vcc, Dec 25, 2007 IP
    blueparukia likes this.
  3. dataman

    dataman Peon

    Messages:
    94
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Something like...

    $value = explode ( __, ${link . '_' . $counter} );
    PHP:
     
    dataman, Dec 25, 2007 IP
    blueparukia likes this.
  4. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #4
    Yup it works (selling_vcc). I didn't know you could do things like that with PHP, thanks a lot man.

    Dataman, your method also works, but I prefer selling_vcc's vecause it looks cleaner.

    Thanks both, rep added,

    BP
     
    blueparukia, Dec 25, 2007 IP