0

我使用一个库将本地 WebSQL DB 同步到服务器,特别是https://github.com/orbitaloop/WebSqlSync。我使用PHP:5.4.7,当我尝试如下获取数组值时,我得到消息

非法字符串偏移 'clientes'

$obj 变量是:

 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"];
}

永远感激任何帮助

4

3 回答 3

2

好像是

$row["data"]["clientes"] // which is an empty array 

或者

$row["data"]["formaspago"][0]["FormaPago"] // which should output "qwerqwe"
于 2013-07-15T16:47:12.047 回答
0

元素 $row["clientes"]["fomaspago"]["FormaPago"]; 确实不存在 - 查看输出:第一行“info”没有该索引,第二行“data”有“clientes”和“fomasgapo”,但没有“clientes”“fomasgapo”。您需要以不同的方式构建数据或以不同的方式循环数据......

于 2013-07-15T16:50:49.323 回答
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; 

}
于 2013-07-16T17:12:08.873 回答