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 #169608 is a reply to message #169597] Sat, 18 September 2010 21:33 Go to previous message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma:
Senior Member
.oO(GarryJones)

> 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.

Why all the if-elses? If you already know what you're looking for, you
can easily use PHP's array functions to reduce this code to 2 or 3
lines. And it would always be the same, whether you have 5 numbers to
check or 500.

But I also agree with the others that there's at least something strange
about the above. I would even say it looks completely wrong by design.
So please post some more details.

Micha
[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: Thu Nov 28 02:45:19 GMT 2024

Total time taken to generate the page: 0.04617 seconds