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

    Join Date
    Mar 2000
    Location
    Ontario, Canada
    Posts
    498
    Rep Power
    18
    How can I remove whitespace from an Array? I've got an array that has several elements that are just whitespace, and I would like to get rid of it to make the process for my document easier. Ex:arr[0] = 71731
    $arr[1] =
    $arr[2] =
    $arr[3] =
    $arr[4] = Printer Friendly WUI - North Bay, Canada Weather Conditions
    $arr[5] =
    $arr[6] =
    $arr[7] =
    $arr[8] =


    I wanna remove 1-4, and 5-8 (and etc.) without having to sort the array (because it gets stored in the array the way i want it to.) I just want to remove the whitespace... I've read through the Arrays section in the manual, and tried everything I could... Any help would be greatly appreciated.



    ------------------
    To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    16
    $count=count($array);
    for($i=0;$i<$count;$i++) {
    if(empty($array[$i]){unset($array[$i]);}
    }

    This is untested and pretty much just a guess... but I don't see why it wouldn't work.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Ontario, Canada
    Posts
    498
    Rep Power
    18
    Nope... still says there's 79 array elements.

    But with some editing, I got it to work. Turns out, all I needed was a shot of array_splice ^_^. Thanks a bunch.

    ------------------
    To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson

    [This message has been edited by cka (edited October 21, 2000).]

    [This message has been edited by cka (edited October 21, 2000).]

Similar Threads

  1. Printing related elements from a multi-dimensional array
    By lisamar1 in forum Perl Programming
    Replies: 3
    Last Post: February 16th, 2004, 10:11 AM
  2. Replies: 2
    Last Post: January 28th, 2004, 12:06 AM
  3. sort: find duplicate string elements in array
    By sciencelife in forum Java Help
    Replies: 3
    Last Post: January 27th, 2004, 01:29 PM
  4. Replies: 1
    Last Post: December 10th, 2003, 09:51 AM
  5. multi dimensional arrays - Can't grasp how to?
    By Kaleina in forum PHP Development
    Replies: 17
    Last Post: November 5th, 2003, 03:18 PM

IMN logo majestic logo threadwatch logo seochat tools logo