繁体   English   中英

如何从数组中获取特定数据,如下所示,在PHP中?

[英]How to get the specific data from an array, shown as below, in PHP?

在这里,您将看到显示数组的图像

我正在使用jquery从现有表发送数据,以便通过mysql保存数据。 但是,我无法从图像上显示的数组中回显或显示任何特定数据。

这是我用来从表中获取数据的代码。

 var output = [], row = 0; $('table').find('tr').each(function (index, obj) { output.push([]); var TDs = $(this).children(); $.each(TDs, function (i, o) { output[row].push($(this).text()); }); row++; }); 

我将其转换为对象。

 var jObject={}; for(i in output) { jObject[i] = output[i]; } 

然后,我将其转换为JSON对象并将其发送到GetGastos.php

 jObject= JSON.stringify(jObject); $.ajax({ type:'POST', cache:false, url:"GetGastos.php", data:{jObject: jObject}, success:function(server){ alert(server); } }); 

这就是我在php上所得到的,该php如图所示打印了数组。

 <?php $data = json_decode($_POST['jObject'], true); foreach($data as $d){ print_r($d); } ?> 

(编辑)如何从第二行中获取值,第二行显示为具有以下值的第二个数组:之前显示的图像中的NULL,2、7和985? 除了将各个值转换成变量外,例如,在$ FirstVar中是否为NULL,在$ SecondVar中是否为2,在$ ThirdVar中为7,以及在$ FourthVar中为985?

您必须使用:not():first-child选择器来排除第一个<tr>

$('table').find('tr:not(:first-child)')...

要么

$('table tr:not(:first-child)')...

暂无
暂无

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

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