/    Sign up×
Community /Pin to ProfileBookmark

how to remove a space from an array

i am having an array with some elements but my problem is that the last element i am getting is a space like this
————————————————————————–

array(4) { [0]=> string(6) “Active” [1]=> string(8) “Inactive” [2]=> string(4) “TEST” [3]=> string(2) ” ” }


————————————————————————–

ie the forth element is a space
how can i remove that space???

-ashish

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYJan 31.2006 — you mean remove the 4th key&value?
Copy linkTweet thisAlerts:
@ashishrathoreauthorJan 31.2006 — yes ,that one with the space
Copy linkTweet thisAlerts:
@NogDogJan 31.2006 — Not tested:
[code=php]
foreach($myarray as $key => $value)
{
if(empty(trim($value))
{
unset($myarray[$key]);
}
}
[/code]
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYJan 31.2006 — tested and working:
[code=php]
<pre>
<?php
$array = array("blue", "red", "yellow", " ", "baboon");
print_r($array);
echo "<br>";


foreach($array as $key => $value){
$value = trim($value);
if(empty($value)){
unset($array[$key]);
}
}

print_r($array);
?>
</pre>
[/code]


nogdog, you miss a closing parenthesis for your if clause.
×

Success!

Help @ashishrathore spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...