0
I have this array in PHP and I must display the users name and email field. But php display an error message:
array(4)
{
[0]=> object(stdClass)#25 (5)
{
["idusuario"]=> string(1) "2"
["nome"]=> string(5) "admin"
["email"]=> string(15) "[email protected]"
["senha"]=> string(3) "123"
["status"]=> string(1) "1"
}
[1]=> object(stdClass)#26 (5)
{
["idusuario"]=> string(1) "3"
["nome"]=> string(5) "teste"
["email"]=> string(15) "[email protected]"
["senha"]=> string(3) "123"
["status"]=> string(1) "0"
}
}
PHP code
<?php
echo $dados["0"]["nome"];
echo $dados["1"]['email'];
?>
Error message:
PHP Error was encountered
Severity: Notice
Message: Undefined index: name
Filename: home/list.php
Line Number: 20
Backtrace
:
PHP Error was encountered
Severity: Notice
Message: Undefined index: email
Filename: home/list.php
Line Number: 21
What is the error message? And how are you trying to do that?
– Miguel
And if you do
$dados[0]->nome;
? Each of the subelements is an object and not an array– Miguel
so work this way: echo $data[0]->name;
– alexjosesilva
with faco to display on foreach ??
– alexjosesilva