vendredi 14 octobre 2016

Illigal String Offset 'id' PHP

This might be duplicate But i couldn't figure it out T _ T Sorry

As i am printing array results coming right from database, its continuously annoying me with error

Illegal string offset 'id'

When i simply print_r result array it gives me following result.

echo "<pre>";
   foreach ($firms as $firm) {
       print_r($firm[0]);
   }
echo "</pre>";

Result:

Array
(
    [id] => 7923
    [rank] => 0
    [name] => CBRE
)
Array
(
    [id] => 7919
    [rank] => 0
    [name] => Aecom
)

But if i try to print 'id' it gives me error:

echo "<pre>";
    foreach ($firms as $firm) {
        echo $firm[0]['id'];
    }
echo "</pre>";

Error:

Illegal string offset 'id'

PS. I am working on laravel5



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire