Jump to content

foreach ARRAY build


phpretard

Recommended Posts

I am trying to echo TESTING as many time as the from element specifies.

 

I know it is all wrong but I have always had a problem wrapping my brains around the array.  I am getting close though.

 

 

This is the general layout.

 

 

$s=$_GET['s'];

if ($s!=''){
$selectbox=array($s);
}

print_r($state_array);  // Array ( [0] => 1 )  <-- This of course yields the number of the option


// FORM ELEMENT

<select name='selectbox' class='select' onchange=\"document.location=this.value\">
<option value=''>Pick A Number</option>
<option value='?page=$page&s=1'>One</option>
<option value='?page=$page&s=2'>Two</option>
<option value='?page=$page&s=3'>Three</option>
<option value='?page=$page&s=4'>Four</option>
</select>	


// I WOULD LIKE TO ECHO TESTING AS MANY TIMES THE VALUE OF $s

IF($s!='') {

$i=0;

foreach($selectbox as $val){

echo $TESTING."<br>";

$i++;
}

}

 

So if I pick 2

 

I would like to see

 

TESTING

TESTING

 

Any help this evening?

Link to comment
Share on other sites

Ok....first of all....just a pet peeve of mine but if you're going to check if the $s variable is empty or not anyway...why not just save yourself the trouble of creating a new variable and just check $_GET first...ok my rant is over there.

 

There's a few things missing in your code snippet or just code in general I guess that's vital to this all, but I'd rather just tell you how do to this

for($i=0;$i   echo "Testing
";
}

 

that's pretty much it

Link to comment
Share on other sites

$s=$_GET['s'];

if ($s!=''){
$selectbox=array($s);
}

 

You're saying....hey, give me that variable.($_GET['s'])..I don't care what's in it or if even exists....just give me it

and then you turn around and say on the VERY next line.....

"wait...uh well maybe I changed my mind....is that variable even real?" maybe I should have used the isset function first to save myself some trouble.....

 

I guess I'm just ranting about the theory of creating TOO many variables before a person can even keep up with the ones they have already.

if there's something wrong with $_GET['s'] then direct the attention to it....don't replicate it

 

it's all in good coding practice

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.