dongye4192 2010-11-21 08:50
浏览 498

如何通过隐藏字段传递数组

here my code

$order[$j][0]="Euclidean Geomethiyil Kodpagugal";
$order[$j][1]=$q16;
$j++;

hidden field-

<input type="hidden" name="hdnTotal" value="<?php echo $gtot; ?>">
<input type="hidden" name="hdnOrder" value="<?php echo $order; ?>">
<input type="submit" value="Place Order">

hdnTotal value is coming in next page but hdnOrder is not. print($_POST['hdnOrder']) print only Array on screen.

  • 写回答

6条回答 默认 最新

  • dongqing4070 2010-11-21 08:56
    关注

    Try json_encode:

    <input type="hidden" name="hdnTotal" value="<?php echo htmlspecialchars(json_encode($gtot)); ?>">
    <input type="hidden" name="hdnOrder" value="<?php echo htmlspecialchars(json_encode($order)); ?>">
    <input type="submit" value="Place Order">
    

    and for get it back, json_decode:

    print(json_decode($_POST['hdnOrder']));
    

    The bonus of this solution is that you will able to manipulate your array at client side easily with JavaScript.

    But why do you want to do that ?

    If it is not for manipulate your data at client side, you create an an unnecessary round trip of your data, that you can easily keep at server side with PHP sessions.

    评论

报告相同问题?

悬赏问题

  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python