douzhongqiu5032 2016-01-08 01:50
浏览 15

在php中创建$ _POST数组中的变量

I am having a $_POST array look like this:

Array
(
    [veryfy_doc_type] => Array
            (
                [0] => 1
                [1] => 2
            )

    [id_number] => Array
            (
                [0] => 3242424
                [1] => 4456889
            )

    [document_issuer] => Array
            (
                    [0] => 1
                    [1] => 3
            )

    [verify_doc_expiry_date] => Array
            (
                    [0] => 2016-01-26
                    [1] => 2015-02-20
            )

    [doc_id] => Array
            (
                    [0] => 15
                    [1] => 16
            )

    [user_id] => Array
            (
                    [0] => 14
                    [1] => 14
            )
)

Using this array I need to get each values into php variables.

I tried it something like this, but it doesn't work for me.

foreach($_POST AS $k => $v) { 
    //print_r($v); 
    list($doc_type, $id_number, $issuer, $expiry_date, $doc_id, $user_id) = $v;
}

echo "Type = $doc_type";

Can anybody tell me how to figure this out. Thank you.

  • 写回答

4条回答 默认 最新

  • douxun2018 2016-01-08 01:52
    关注

    So you want to reference each of the sub-array values while looping the main array... maybe something like this?

    // Loop one of the sub arrays - you need to know how many times to loop!
    foreach ($_POST['veryfy_doc_type'] as $key => $value) {
        // Filter the main array and use the $key (0 or 1) for the callback
        $rowValues = array_map(function($row) use ($key) {
            // Return the sub-array value using the $key (0 or 1) for this level
            return $row[$key];
        }, $_POST);
    
        print_r($rowValues);
    }
    

    Example: https://eval.in/498895

    This would get you structured arrays for each set of data.

    From here I'd suggest you leave the arrays as they are rather than exporting to variables, but if you wanted to you you could use the list() as in your example.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大