array problem

Discussion in 'PHP' started by dracula51, Nov 21, 2009.

  1. #1
    look at these codes plz
    $a = array('aw' => 'buw', 'bw' => 'dsf');
    
    $b = "['aw']";
    
    echo $a.$b;
    Code (markup):
    i wanted the result buw for that but its showing Array['aw']

    i know if i use $a['aw'] it will work, but for some reason i need to do it such way


    tnx in advance
     
    dracula51, Nov 21, 2009 IP
  2. b.krishna

    b.krishna Well-Known Member

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    106
    #2
    You can use echo $a[$b]; this will work. The way your doing is used for string concatenation not for array mapping.
     
    b.krishna, Nov 21, 2009 IP
  3. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #3
    
    echo $a['aw'];
    
    PHP:
     
    AsHinE, Nov 21, 2009 IP
  4. dracula51

    dracula51 Peon

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    why ppl do not read fully b4 reply !!!

    btw, @b.krishna: not working man! actually my variable will be like this: $var['som']['data']['link']

    the array $var will be created in the php file. but ['som']['data']['link'] is stored in mysql db.

    so i wanted to get it maybe in variable $b....so it will be $b = ['som']['data']['link']
    thats why i tried like that ($var.$b) to show the array's value
     
    dracula51, Nov 21, 2009 IP
  5. ShadyStudent

    ShadyStudent Peon

    Messages:
    341
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You need to step back and explain what you are trying to do rather than trying to come up with a solution yourself and forcing us to get that to work for you. It is more than likely that as a collective we will be able to come up with a better solution to your overall problem.
     
    ShadyStudent, Nov 21, 2009 IP
  6. emed

    emed Peon

    Messages:
    70
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6
    $a = array('aw' => 'buw', 'bw' => 'dsf');
    $b = "['aw']";
    
    eval('echo $a'.$b.';');
    
    //OR this if you want to save the result
    eval('$c = $a'.$b.';');
    echo $c;
    PHP:
     
    emed, Nov 21, 2009 IP
  7. dracula51

    dracula51 Peon

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    @ShadyStudent: i told that on my 2nd post...i gave full array

    @emed: yo...it works. tnx man. thank you very much :)
     
    dracula51, Nov 21, 2009 IP
  8. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #8
    could just use $a{$b}

    EDIT: NVM, you have it
     
    JAY6390, Nov 21, 2009 IP
  9. getquicksolution

    getquicksolution Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    $a = array('aw' => 'buw', 'bw' => 'dsf');

    $b = "['aw']";

    $c=$a.$b;
    echo $c;
     
    getquicksolution, Nov 21, 2009 IP