0

I have an array in php called: $tmpArrayFechas.

The array when printed outputs like this:

[{"fecha":{"0":"2018-12-04"},"id":{"0":"34732"},"quedanplazas": 
{"0":"42"}},{"fecha":{"0":"2018-12-11"},"id": 
{"0":"34733"},"quedanplazas":{"0":"55"}},{"fecha":{"0":"2018-12- 
18"},"id":{"0":"34734"},"quedanplazas":{"0":"52"}}]

I only need the id in the array. I have tried this and many other ways:

echo $tmpArrayFechas[0].id["0"];

Above give this error: Notice: Use of undefined constant id - assumed 'id' in /Users/helen/Documents/Web/htdocs/pas/restofform.php on line 51 [i

Helenp
  • 143
  • 2
  • 15
  • PHP does not use "Dot Notation" for accessing object members. – MonkeyZeus Nov 29 '18 at 20:26
  • with coma same error, doing like this $tmpArrayFechas[0]->id["0"]; get error Notice: Trying to get property of non-object in – Helenp Nov 29 '18 at 20:35
  • ok, se is duplicated, have read that file, and still don´t get it.... If I do this: $tmpArrayFechas = json_decode($tmpArrayFechas); print_r($tmpArrayFechas); print_r($tmpArrayFechas->id[0]); outputs this: Array ( [0] => stdClass Object ( [fecha] => stdClass Object ( [0] => 2018-12-04 ) [id] => stdClass Object ( [0] => 34732 ) [quedanplazas] => stdClass Object ( [0] => 42 ) ) [1] => stdClass Object ( [fecha] => stdClass Object ( [0] => 2018-12-11 Notice: Trying to get property of non-object in – Helenp Nov 29 '18 at 20:50
  • That is a completely new error. Your `print_r()` clearly shows you that `$tmpArrayFechas` is an indexed array so it is not an object and has no immediate member named `id`. Make sure to fully understand `print_r()`'s output or else you will fail again and again and again. – MonkeyZeus Nov 30 '18 at 13:48

0 Answers0