/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] comma + array

Hi all,

I have some values in a array defined as number[] in a list box.

foreach($_POST[‘number’] as $key=>$value)
{
$reg .=$value.”,”;
}

So if i select 1 2 3 then the above code is producing 1,2,3, but i want to have it as 1,2,3

So number of commas is one less then number of elements present in a array and it will be always true.

I am running the above foreach loop but everytime I am getting a comma at the last of the array values……Could you please suggest me how can i remove the last comma

Thanks
Raj

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Jan 08.2007 — [code=php]$tmpARRAY = array();
foreach($_POST['number'] as $value) {
$tmpARRAY[] = $value;
}
$reg = implode(",", $tmpARRAY);[/code]
Copy linkTweet thisAlerts:
@raj_2006authorJan 08.2007 — Its simply great...feeling shame now......... :p

Thanks mate,

Raj
Copy linkTweet thisAlerts:
@NightShift58Jan 08.2007 — You're welcome!
×

Success!

Help @raj_2006 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.12,
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,
)...