当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Illegal string offset in array

问题描述:

I use a library for Synchronize a local WebSQL DB to a server specifically https://github.com/orbitaloop/WebSqlSync.

I use PHP: 5.4.7,

When I try to get the array values ​​as follows, I get the message

Illegal string offset 'clientes'

the $obj var is:

 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

(

)

)

)

this is the loop

foreach ($obj as $row => $value) {

echo $row["clientes"]["fomaspago"]["FormaPago"];

}

eternally grateful for any help

网友答案:

it seems to be

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

or

$row["data"]["formaspago"][0]["FormaPago"] // which should output "qwerqwe"
网友答案:

The element $row["clientes"]["fomaspago"]["FormaPago"]; does indeed not exist - look at the output: the 1st row "info" does not have that index, the 2nd row "data" has "clientes" and also "fomasgapo", but does not have a "clientes" "fomasgapo". You need to either structure your data differently or loop through it differently...

网友答案:

thanks to all but the only way that worked was as follows:

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; 

}
分享给朋友:
您可能感兴趣的文章:
随机阅读: