#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    49
    Rep Power
    6

    Multi Arrays While Loop Question?


    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!

    PHP Code:
    $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>';
                 }
         } 
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,141
    Rep Power
    9398
    The subarrays aren't using keys.

    There are only two values: the region and the station name. You're trying to get three values out of it. I don't see how that can work.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    49
    Rep Power
    6
    Hi requinix

    Appreciate the reply. I've figured out what I did wrong. I think I'm doing it correctly.

    PHP Code:
         foreach($newschannels as $channels => $data){
            
    // echo "$channels".'<br>';
                 
    foreach($data as $key => $value){
                    echo 
    "Region: $channels, Channel: $value".'<br>';
                 }
         } 
    Thanks!
    Last edited by scm22ri; October 9th, 2012 at 05:41 PM.

IMN logo majestic logo threadwatch logo seochat tools logo