简体   繁体   English

如何在php中从$ _POST var_dump中拆分数据

[英]how to split the data from $_POST var_dump in php

hi guy's this is my first time using var_dump in php function. 嗨,大家好,这是我第一次在php函数中使用var_dump i am really don't know how to split the data from that var_dump maybe someone can help me to give an example for split that data. 我真的不知道如何从var_dump拆分数据,也许有人可以帮我举一个拆分数据的示例。 i hope the method is simple for i can understand. 我希望该方法简单易懂。 i have try to search it in this forum and i can understand it. 我试图在这个论坛中搜索它,我可以理解。

this is the data i have got from `var_dump 这是我从`var_dump获得的数据 来自Var_dump的数据

please give me a simple example for that. 请给我一个简单的例子。 an please explain it for me. 请为我解释一下。 i just use this code for get the data. 我只是使用此代码来获取数据。 because its my 1st time. 因为这是我的第一次

<?php
include('../../Connections/koneksi.php');
$tableData = var_dump($_POST);

echo $array;
?>

This is the actual data http://jsfiddle.net/minervaz/us4a9gkL/ 这是实际数据http://jsfiddle.net/minervaz/us4a9gkL/

  • You can't use echo to display an object or array.So use var_dump() or print_r() 您不能使用echo显示对象或数组,因此请使用var_dump()print_r()

Javascript code : JavaScript代码:

<script type="text/javascript">
    $(document).on('click','#display_data',function(e){
    var convertTableToJson = function()
        {
            var rows = [];
            $('.table-bordered tr:has(td)').each(function(i, n){
                var $row = $(n);
                rows.push([
                    $row.find('td:eq(0)').text(),
                    $row.find('td:eq(1)').text(),
                    $row.find('td:eq(2)').text(),
                    $row.find('td:eq(3)').text(),
                    $row.find('td:eq(4)').text(),
                    $row.find('td:eq(5)').text(),
                    $row.find('td:eq(6)').text(),
                    $row.find('td:eq(7)').text(),
                ]);
            });
            return JSON.stringify(rows);
        };
   var data = convertTableToJson();
    $.ajax({
    data: { 'table-bordered': data },  
    type:"POST",
    url:"../php/tagihan/save_data.php",
            success: function(data){
                //alert(JSON.stringify(data));
                console.log(data);
            }            
    });

});
</script>

PHP CODE : PHP代码

if(isset($_POST['table-bordered'])){
    $array=json_decode($_POST['table-bordered'],true);
    print_r($array);


}

Output 产量

Array
(
    [0] => Array
        (
            [0] => 101200
            [1] => WCB
            [2] => 101
            [3] => 5006540050
            [4] => 1
            [5] => 10.08.2017
            [6] => 23.970
            [7] => KG
        )

    [1] => Array
        (
            [0] => 101200
            [1] => WCB
            [2] => 101
            [3] => 5006539985
            [4] => 1
            [5] => 10.08.2017
            [6] => 42.970
            [7] => KG
        )

)   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM