php - 如何在 HTML 文件中传递数组?
问题描述
我的 HTML 文件中有一个标签,我的 PHP 文件中有“myfunc”函数。如何将 href 中的数组传递给我的“myfunc”函数?
<a class="btn btn-danger" href="<?php echo myfunc("this is arg1 witch is string", ['id']); ?>">delete</a>
这是我的 PHP 函数:
function myfunc($str,$param=[])
{
return true;
}
解决方案
a中不能有数组,URL
如果一定要encoded
格式的话,我写了一个demo代码,看看能不能解决你的问题↓↓
查看
<?php
$id = array('1', '2');
// convert the array to JSON objects and then convert the string(object) to query part of the URL.
$id = urlencode(json_encode($id));
?>
<a class="btn btn-danger" href="<?php echo base_url("home/form/this is arg1 witch is string/{$id}"); ?>">delete</a>
控制器
function form($str, $param){
echo urldecode($str); // convert the URL string back into its original form
echo '<br>';
print_r(json_decode(urldecode($param))); // Convert the URL string into encoded form and then convert it back to an array.
}
输出
this is arg1 which is string
Array ( [0] => 1 [1] => 2 )
推荐阅读
- angular - Angular 8 - 如何使用 ngx-permissions 授权权限而不是角色?
- typo3 - “控制器不存在。反射失败。” TYPO3
- mysql - MySQL 默认查询
- corda - 使用 Corda `vaultQueryBy` stateRef 的 `txhash` 返回交易的所有状态
- java - 不知道为什么 typeConvertor 不起作用
- scala - Spark 2.1.x 数据集 API - 了解 groupByKey 和 reduceGroups 行为
- r - 合并在 R 中缺少一些值
- powershell - 将 Connect-SPOService 与 Powershell 6(核心版本)一起使用
- powershell - Office 365 使用 Powershell 批量删除电子邮件
- activemq-artemis - 现在如何将 JmsConfiguration 设置为 EmbeddedActiveMQ?