FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » for each syntax
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: for each syntax [message #169604 is a reply to message #169597] Sat, 18 September 2010 20:21 Go to previous messageGo to previous message
spambait is currently offline  spambait
Messages: 35
Registered: September 2010
Karma:
Member
In article <6a86e2b1-a632-4415-9d1b-608bf205ffd9(at)k30g2000vbn(dot)googlegroups(dot)com>, GarryJones <morack(at)algonet(dot)se> wrote:
> I need to automatically write a few lines of code with php.
>
> This is the output i need
> if ($_POST['resmalval109'] == 109) {
> $resmalval=109;
> } elseif ($_POST['resmalval110'] == 110) {
> $resmalval=110;
> } elseif ($_POST['resmalval111'] == 111) {
> $resmalval=111;
> } elseif ($_POST['resmalval112'] == 112) {
> $resmalval=112;
> } elseif ($_POST['resmalval113'] == 113) {
> $resmalval=113;
> } elseif ($_POST['resmalval114'] == 114) {
> $resmalval=114;
> } elseif ($_POST['resmalval115'] == 115) {
> $resmalval=115;
> } else {
> // something else
> }
>
> The required numbers just happen to be sequential at the moment, but
> over time these values will change, Instead of manually writing the
> above code every time I want to create it with php.
>
> I have the required numbers in an array.
> $arr_single = array(109,110,111,112,113,114,115);
>
> So my guess is using "for each" I can write in each number where it is
> needed until the array is empty. I can't use the $var++ trick as these
> numbers can (for example) change to
>
> $arr_single = array(109,111,112,113,115);
>
> Any help in right direction greatly appreciated.,,
>
Perhaps if you'd describe what it is you're actually trying to -- not the
method you've chosen to try to do it -- we could be of more help. Please give
a general description of the task. There may be other, much simpler, methods
of getting it done.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: Illegal variable _files
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 01:54:10 GMT 2024

Total time taken to generate the page: 0.04478 seconds