我使用库来将本地WebSQL DB同步到服务器https://github.com/orbitaloop/WebSqlSync。 我使用PHP:5.4.7, 当我尝试按如下方式获取数组值时,我收到消息
非法字符串偏移'clientes'
$ obj var是:
Array
(
[info] =>
[data] => Array
(
[clientes] => Array
(
)
[conceptos_gastos] => Array
(
)
[formaspago] => Array
(
[0] => Array
(
[idFormaPago] => 10
[FormaPago] => qwerqwe
[Dias] => 1
[Cuotas] => 1
[last_sync_date] =>
)
)
[listaprecios] => Array
(
)
[producto] => Array
(
)
[repartidores] => Array
(
)
[tipodocumento] => Array
(
)
[vehiculos] => Array
(
)
[zonas] => Array
(
)
)
)
这是循环
foreach ($obj as $row => $value) {
echo $row["clientes"]["fomaspago"]["FormaPago"];
}
永远感激任何帮助
答案 0 :(得分:2)
似乎是
$row["data"]["clientes"] // which is an empty array
或
$row["data"]["formaspago"][0]["FormaPago"] // which should output "qwerqwe"
答案 1 :(得分:0)
元素$ row [“clientes”] [“fomaspago”] [“FormaPago”];确实不存在 - 看输出:第一行“info”没有那个索引,第二行“data”有“clientes”和“fomasgapo”,但没有“clientes”“fomasgapo”。 您需要以不同的方式构建数据或以不同方式循环它...
答案 2 :(得分:0)
感谢除了唯一可行的方法之外的所有方法如下:
foreach($obj->data->formaspago as $formaspago) {
print " id ".$formaspago->idFormaPago;
print " Formapago ".$formaspago->FormaPago;
print " dias ".$formaspago->Dias;
print " cuotas ".$formaspago->Cuotas;
print " lastsyncdate ".$formaspago->last_sync_date;
}
foreach($obj->data->clientes as $formaspago) {
print " id ".$formaspago->IdCliente;
print " Cliente ".$formaspago->Cliente;
}