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 #169602 is a reply to message #169597] Sat, 18 September 2010 20:19 Go to previous messageGo to previous message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma:
Senior Member
On 18-09-10 22:02, 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.,,
>

<?php

$arr_single = array(109,110,111,112,113,114,115);

for ($x=0; $x<sizeof($arr_single); $x++) {
echo "x:$x e:".$arr_single[$x]."<br>";
}

?>


--
Luuk
[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:35:12 GMT 2024

Total time taken to generate the page: 0.04766 seconds