Link to home
Start Free TrialLog in
Avatar of deharvy
deharvy

asked on

Removing Blank Key from Array

I have an array that has an empty key set. I tried to remove it, but it's not working.

Here is the output:

Array ( [ ] => [200] => )

---------------

Here is the code I currently have:

            foreach($keys as $key => $value) {
                  if($key == "" || $key == " ") {
                unset($keys[$key]);
          }
    }

Can you let me know what I'm doing wrong?
SOLUTION
Avatar of Greg Alexander
Greg Alexander
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deharvy
deharvy

ASKER

array(22) { [" "]=> NULL [200]=> NULL }
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deharvy

ASKER

Both these solutions work fine. Since my keys are numbers, was also able to use:

if($key == "" || $key < 1) {