Jump to content

wierd problem with array !!


asmith

Recommended Posts

i've got a  $_POST[john] which is an array (containing the values of a multiple select box)

$_POST[john] = array("1" ,"2" , "3" )

 

 

$fruit = array ("1" => "apple" ,"2" => "orange" , "3" => "banana" )

 

for some reasons i had to do something like this ,

 

$a = array_rand($_POST[john]);

$b = $_POST[john][$a];

 

 

echo $fruit[$b];

 

all the things run fine, no problem.

when the user click on the submit button,  $_POST[john] will be saved in a session. in the other page, there's a back button, which will redirect to this page. (IT WILL PUT THE SESSION VALUE INTO THE $_POST[john] AGAIN)

 

here comes the problem , when i click on the back button, there is no echo from $fruit[$b] ! 2 times of the 3 ! sometimes it shows "apple" which means it has been 1 , but when it choses the 2 or 3 , it dosn't show orange and banana.

what is this wierd problem  ? why one value of the array works ?

 

(i have echoed and print_r of all the  $_POST[john], $fruit , $a , $b  when i click the back button ,all shows the values, but i don't know why only this line : $fruit[$b] works 1 in 3 times !! )

 

 

 

Link to comment
Share on other sites

nono , the back button is mine,

 

<input type="submit" value="back" name="back">

 

 

if have , if isset($_POST[back])

then put all sessions variables to $_POST[...]  , then load the fist page again  ,

i said all the things run fine except this array.

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.