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
https://forums.phpfreaks.com/topic/81173-wierd-problem-with-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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