How to pass an array parameter through a hyperlink

Source: Internet
Author: User
-

In general, we do not use this approach to pass array parameters to the destination URL. The common practice is to commit array parameters by expressing them, or to submit them asynchronously via an AJAX form.

However, usually the word is for the special existence, if you really need to use non-mainstream way to pass the array parameters, the webmaster also prepared for you an imperfect solution. Take a look at the following code:

<meta charset= ' utf-8′>
<pre>

<?php
if ($_get[' names ']) {
$arr =explode ('-', $_get[' names ']);
Print_r ($arr);
Exit ();
}
$names = Array ("11″," 22″, "33″");
$arg =implode ('-', $names);
$url = "http://localhost/root/bd.php?names=". $arg;
Header ("Location: $url");
?>

Code Description:

1, we first convert the array to a string, and then receive the parameters at the target URL, and then restore the string to an array

2. This method only applies to one-dimensional arrays

3, the array can not be too large, or will exceed the maximum URL length

4, the connector suggested using '-' or '/', not recommended ', '

Obviously, the above processing can meet the requirements of the URL passing array, but it is limited, not perfect, and deal with a little bit of difficulty. Still, it does solve some of the problems, hoping that the webmaster's scheme will help programmers who are experiencing this problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.