I have an associative array (data) that contains data and another associative array (other values) within it, the problem is that I can only read the data contained before the array (other values) throwing the error Catchable fatal error: Object of class stdClass could not be converted to string
this in php, if I print it by console everything is correct, what I want is to be able to access the values of the array (other values);
Jquery
var otrosValores={
val1:"valor 1",
val2:"valor 2",
val3:"valor 3"
}
var dato={
nombre:"aqui el nombre",
apellido:"aqui el apellido",
rut:"aqui el rut",
otros:otrosValores,
}
console.dir(dato)
$.ajax({
url : 'admin/controlador.php',
type : 'POST',
cache : false,
data : "op=saveFicha&datos="+JSON.stringify(dato),
success: function(resultado){
$(".resultado").html(resultado)
}
})
Php
$datos=json_decode($_POST["datos"]);
foreach ($datos as $key => $value) {
echo $key," => ",$value,"<br>";
if($key=="otros"){
foreach ($key as $key2 => $value2) {
echo $key2," => ",$value2;
}
}
}