Multi Arrays While Loop Question?

Discussion in 'PHP' started by scm22ri, Oct 9, 2012.

  1. #1
    Hi Everyone,


    I'm not sure why when I loop through my array I'm getting numbers associated with items in my array.


    How would I get rid of those numbers?


    My syntax is below. Thanks!


    $newschannels = array('Local'=>array('ABC6 News','CBS Stations','Local Fox News','NBC News'),    'Regional'=>array('YES Network','NESN'),    'National'=>array('Fox News','CNN','MSNBC'),    'International'=>array('BBC News','France International','Ireland International'));         foreach($newschannels as $channels => $data){        echo "$channels".'<br>';             foreach($data as $key => $value){                echo "Region: $key, Channel: $value".'<br>';             }     }
    PHP:

     
    scm22ri, Oct 9, 2012 IP
  2. plussy

    plussy Peon

    Messages:
    152
    Likes Received:
    5
    Best Answers:
    9
    Trophy Points:
    0
    #2
    Each array value has a key. This is needed to access that value. If you don't provide one, php will automatically number them.

    So bottom line is you can't get just rid of those numbers. The question is what do you want to display in the place where the $key is currently displayed.
     
    plussy, Oct 10, 2012 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    What is Region: $key supposed to output?

    I don't see any region in here unless the Local, Regional, etc. is supposed to be a region.
     
    jestep, Oct 10, 2012 IP