Ok I'm new 开发者_如何学JAVAto php and I'm already loving my progress. So now I'm doin something just for fun. I have 2 pages. The first page has a link to the second page like this:
<h2>You can click the link below to skip to the next page</h2>
<a href="page2.php?food=rice&dress=lacoste">Click Here</a>"
Now on the second page, I successfully got the value for food by using the get array like this
$food = $_GET['food'];
echo $food;
Now my problem is, how do I add a new item to the array like for instance chicken. Is this possible? If it is please show me how. Thanks guys =)
You will need to make your link look something like this
<a href="page2.php?food[]=rice&food[]=chicken&dress=lacoste">Click Here</a>"
Note the []
at the end of the parameter. This means the argument will be passed to PHP as an array. If you do a print_r($_GET['food']);
you will get an array with both rice
and chicken
as elements
you could set food=rice-chicken
in the url and break the string up in php.
精彩评论