Question about arrays (PLZ HELP!)

Discussion in 'PHP' started by iNfans, Jan 14, 2007.

  1. #1
    So, I have a file script.php:
    <?
    $data1 = array("name1" => "john", "name2" => "kevin");
    $data2 = array("name1" => "tom", "name2" => "irvin");
    ?>

    Now I want to open this file like "script.php?ch=data1" and when its opened on page must be printed text "john kevin" (by <? echo $something ?>), or when I open page "script.php?ch=data2" on page is printed "tom irvin". How can I do that? (plz post an example)

    Please forgive me for this newb question and for my pure english.
     
    iNfans, Jan 14, 2007 IP
  2. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if ( isset($_GET['ch']) && isset($$_GET['ch']) && is_array($names=$$_GET['ch']) ) {
        echo $names['name1'].' '.$names['name2'];
    }
    PHP:
    Like that?
     
    rodney88, Jan 14, 2007 IP
  3. iNfans

    iNfans Well-Known Member

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Yes, but when I'm used this script, it printed "john kevinArray". I dont need two names together, I need to use this script like:

    script.php:
    "<?
    $data1 = array("name1" => "john", "name2" => "kevin");
    $data2 = array("name1" => "tom", "name2" => "irvin");
    ?>
    <html>
    <body>
    My name is <?php echo $name1; ?> (name1 from data1)
    My bro name is <?php echo $name2; ?> (name2 from data1)
    </body>
    </html>
    "
    So when I open script.php?ch=data1 will be printed:
    "
    My name is john
    My bro name is kevin
    "

    AND THANK YOU VV MUCH FOR FAST REPLY!
     
    iNfans, Jan 14, 2007 IP
  4. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?php
    
    if ( isset($_GET['ch']) && isset($$_GET['ch']) && is_array($names=$$_GET['ch']) ) {
        $name1=$names['name1'];
        $name2=$names['name2'];
    }
    
    ?>
    <html>
    <body>
    <?php echo $name1; ?>
    <br /><br />
    <?php echo $name2; ?>
    </body>
    </html>
    PHP:
     
    rodney88, Jan 14, 2007 IP
    iNfans likes this.
  5. iNfans

    iNfans Well-Known Member

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #5
    thank you!
     
    iNfans, Jan 14, 2007 IP