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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Both these solutions work fine. Since my keys are numbers, was also able to use:
if($key == "" || $key < 1) {
if($key == "" || $key < 1) {
ASKER