Home > Article > Backend Development > Introduction to the method of passing array parameters through php hyperlinks
In normal PHP programming, if we need to pass array parameters, we usually submit them asynchronously through the for form or ajax. Today I will introduce to you how to deliver it through hyperlinks for your reference.
Sample code: <?php /** * 超链接传递数组参数 * site bbs.it-home.org */ 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”); ?> Instructions: 1. First convert the array into a string, then receive the parameters in the target URL, and then restore the string to an array. 2. This method only applies to one-dimensional arrays, and the array cannot be too large, otherwise it will exceed the upper limit of the URL length. 3. It is recommended to use '-' or '/' as the connector, but it is not recommended to use ',' Although the above code implements simple array transfer requirements, it is not recommended for use in a production environment and is only for your learning reference. |