/    Sign up×
Community /Pin to ProfileBookmark

Simple Loop Through Value Names

I’m dumb. I’m passing some values from a form page to another PHP page for display. I just need help looping through the values and creating a new variable. The number of values will vary.

Form field names and values being posted:

priceOption1: 123
priceOption2: 368
priceOption3: 3678

I need to be able to take these values (regardless of how many) and create a new variable like this with spaces between the values:

priceOptions = “123 368 3678”;

Note: I cannot use priceOption[]. The form is pretty complex and is already set-up this way.

Thank you for your help!!!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@littlenedAug 19.2006 — [code=php]<?php

$priceoption1 = 123;
$priceoption2 = 456;
$priceoption3 = 789;

$count = 1;
$NewPriceOption = '';

// $v_name is the name of the dynamic variable
$v_name = "priceoption".$count;

while (${$v_name} <> '') {
$NewPriceOption = $NewPriceOption . " " . ${$v_name};
$count ++;
$v_name = "priceoption".$count;
}

echo $NewPriceOption;

?>[/code]
×

Success!

Help @msmith29063 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.18,
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,
)...