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 #169612 is a reply to message #169610] Sun, 19 September 2010 00:33 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 9/18/2010 7:17 PM, Doug Miller wrote:
> In article<i737cr$a2i$1(at)news(dot)eternal-september(dot)org>, Jerry Stuckle<jstucklex(at)attglobal(dot)net> wrote:
>> On 9/18/2010 4:02 PM, GarryJones 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.,,
>>>
>>
>> I agree with Doug. Any time I see something like this, I know someone
>> is trying to force something which is easy.
>>
> I don't see it quite that way, Jerry -- more that he's latched on to one
> particular method of solving a problem, and is determined to solve the problem
> using that method no matter what. Sometimes one needs to step back and think
> "What am I really trying to accomplish here?". Without doing so, it's not
> possible to consider alternative methods of solving the problem.

Which is the same as what I was saying - just different words.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[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: Sun Nov 24 08:25:24 GMT 2024

Total time taken to generate the page: 0.04690 seconds