2

I'm connecting my laravel application with firebase and I successfully get the following response:

array:1 [▼
    "-KvJja_r0beLtdoRc29f" => array:5 [▼
        "accepted" => "true"
        "date" => "1/10/2017"
        "hour" => "0:43"
        "numberOfPeople" => ""
        "tableInfo" => ""
    ]
]

I want to know how to get the value "-KvJja_r0beLtdoRc29f" from this response. I tried looping with foreach, but I get the inner data not the key.

I tried

@foreach($reservations as $reservation)

then printing the results but I get the

"accepted" => "true"
"date" => "1/10/2017"
"hour" => "0:43"
"numberOfPeople" => ""
"tableInfo" => ""

How can I do this?

2
  • 1
    The docs have an example on the syntax. Commented Jan 18, 2018 at 16:12
  • 1
    thanks, i didn't notice it. Commented Jan 18, 2018 at 16:16

1 Answer 1

5

Use can use $key inside foreach() to get key value. Do like below:-

@foreach($reservations as $key=> $reservation)
  echo $key; // output -KvJja_r0beLtdoRc29f

Sample Output:- https://eval.in/937628

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.