0

I don't understand how the display of an array work. When I print_r($context->correspondance) I get this :

Array ( [0] => Array ( [vdepart] => Biarritz [vcorrespondance] => [vid] => 864 [vtarif] => 45 [vnbplace] => 1 [vheuredepart] => 12 [vcontraintes] => soyez GENTILS ) [1] => Array ( [vdepart] => Biarritz [vcorrespondance] => [vid] => 817 [vtarif] => 4 [vnbplace] => 3 [vheuredepart] => 4 [vcontraintes] => no,n ) [2] => Array ( [vdepart] => Biarritz [vcorrespondance] => [vid] => 762 [vtarif] => 31 [vnbplace] => 3 [vheuredepart] => 6 [vcontraintes] => chien autorise ) [3] => Array ( [vdepart] => Biarritz [vcorrespondance] => [vid] => 846 [vtarif] => 862 [vnbplace] => 1 [vheuredepart] => 3 [vcontraintes] => tt ) [4] => Array ( [vdepart] => Biarritz [vcorrespondance] => [vid] => 863 [vtarif] => 1 [vnbplace] => 1 [vheuredepart] => 1 [vcontraintes] => Moi, Nicolas Guégan, vous invite tous à mon anniversaire le 18/12/2022 au trampoline park d'Avignon pour s'amusert tous ensemble ! N'héitez pas à me contacter via mon adresse mail : nicolas.guegan@alumni.univ-avignon.fr Je vous aime tous ! ) [5] => Array ( [vdepart] => Biarritz [vcorrespondance] => [vid] => 866 [vtarif] => 2 [vnbplace] => 3 [vheuredepart] => 10 [vcontraintes] => Salut ) )

But when I just want to display only one column by doing

echo($context->correspondance->vdepart) or echo($context->correspondance[0]->vdepart[0])

I get this :

 Trying to get property of non-object in file...

How can I display this ? Thank you in advance for your answers !

il_raffa
  • 5,090
  • 129
  • 31
  • 36
  • 1
    `echo($context->correspondance[0]['vdepart'])` – Jared Dec 20 '22 at 18:23
  • 1
    There are no objects in the data, only arrays. So just stop using object syntax, and use array syntax instead. – ADyson Dec 20 '22 at 18:24
  • Duplicate of [How can I access an array/object?](https://stackoverflow.com/questions/30680938/how-can-i-access-an-array-object). As said before, the thing which contains videpart is an array not an object, so stop using arrow syntax to try and access it. The error message about a "non-object" is trying to tell you that, and the big word "array" in the print_r data makes it very obvious. So I can only assume that you don't realise that `->` is only for accessing object properties, not array properties. – ADyson Dec 22 '22 at 13:37

2 Answers2

0

$context is an object while its property corresponance is an array. You get the contents of vdepart this way:

print_r($context->correspondance[0]['vdepart']);
Skip
  • 95
  • 8
0

Try this:

<?php

echo '<pre>';

print_r($context->correspondance[0]['vdepart']);

// or

var_dump($context->correspondance[0]['vdepart']);

echo '</pre>';

?>
Peter
  • 59
  • 3