foreach counting...

Discussion in 'PHP' started by redhits, Aug 17, 2007.

  1. #1
    <?php

    foreach($_GET as $x) {
    echo "$x <br />";
    }

    ?>

    Lets say we named this file, index.php
    We put into the address bar:

    /index.php?name=x&page=y&other=z

    The code would output:

    x
    y
    z



    Fine that's very nice, but i would like to known how i can also known the variable name, not just the data handled by variable...
    like how i can do an

    - "name x "
    - "page y"
    - "other z"
    ?!
     
    redhits, Aug 17, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    nico_swd, Aug 17, 2007 IP
  3. redhits

    redhits Notable Member

    Messages:
    3,023
    Likes Received:
    277
    Best Answers:
    0
    Trophy Points:
    255
    #3
    foreach($vector as $easy -> $country){
    echo "<br>$country";

    foreach($easy as $data -> $location) {
    echo "<br>$location";

    }




    this is not working :(
     
    redhits, Aug 17, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    This code has nothing to do with the code I gave you. Nothing...
     
    nico_swd, Aug 17, 2007 IP
    redhits and Crazy_Rob like this.
  5. redhits

    redhits Notable Member

    Messages:
    3,023
    Likes Received:
    277
    Best Answers:
    0
    Trophy Points:
    255
    #5
    yes man... but take a look

    i want to process some data with 2 dimensions matrix like


    $a['country1']['country2']='100km'; got it?!
     
    redhits, Aug 17, 2007 IP
  6. redhits

    redhits Notable Member

    Messages:
    3,023
    Likes Received:
    277
    Best Answers:
    0
    Trophy Points:
    255
    #6
    Even this is not working :(

    foreach($vector as $easy){

    foreach($easy as $data -> $rank){
    echo "$data $rank";
    }


    }



    Catchable fatal error: Object of class stdClass could not be converted to string in C:\www\g2\easy.php on line 47
     
    redhits, Aug 17, 2007 IP
  7. redhits

    redhits Notable Member

    Messages:
    3,023
    Likes Received:
    277
    Best Answers:
    0
    Trophy Points:
    255
    #7
    uhhh i did an -> insted of => :(
     
    redhits, Aug 17, 2007 IP
  8. redhits

    redhits Notable Member

    Messages:
    3,023
    Likes Received:
    277
    Best Answers:
    0
    Trophy Points:
    255
    #8
    problem solved :(
     
    redhits, Aug 17, 2007 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    Lol, this is a completely different thing, and has nothing to do with your initial question. I gave you the solution to the answer you asked in your first post. If you can't explain what you want, nobody will be able to help.

    Take a look at my code again. Or even at the link I posted. I'm not going to tell you where your error is, because it's too easy. :D

    EDIT:

    Good job.
     
    nico_swd, Aug 17, 2007 IP
  10. redhits

    redhits Notable Member

    Messages:
    3,023
    Likes Received:
    277
    Best Answers:
    0
    Trophy Points:
    255
    #10
    Yes, thanks for your help anyway :) good job from you to :)
    green added
     
    redhits, Aug 17, 2007 IP
    nico_swd likes this.