Ming An
Ming An

Reputation: 155

Can someone explain what kind structure does this variable have?

for($i = 0; $i < count($all_events); $i++) {

    $temp_event = $this->model_events->find_event($all_events[$i]['event_id']);
    $data['attending_events'][$i]['event_id'] = $temp_event[0]['event_id'];
    //return everything from the ticket table based on the event id
    $ticket_data = $this->model_tickets->get_ticket_owner($data['attending_events'][$i]['event_id']);
    for($j = 0; $j < count($ticket_data); $j++) {
        $data['attending_events'][$i]['tickets'][$j] = $ticket_data[$j];
    }
        $data['attending_events'][$i]['e_name'] = $temp_event[0]['e_name'];
        $data['attending_events'][$i]['e_date'] = $temp_event[0]['e_date'];
        $data['attending_events'][$i]['e_price'] = $temp_event[0]['e_pricetemp'];
        $data['attending_events'][$i]['e_is_address_hide'] = $temp_event[0]['e_is_address_hide'];
}

I'm new to php, I'm getting really confused by the variable structure. As you can see in the code above, there is a variable called $data. This is the variable that I don't understand.

First of all, in $data['attending_events'], is attending_events an index, just like array[0], or something else?

And what is the number $i in $data['attending_events'][$i]['e_price'].

Finally what is this '$data['attending_events'][$i]['tickets'][$j]'? Is this another layer?

I'm fimiliar with C++. This is $data variable something like a multidimentional vector?

Upvotes: 0

Views: 20

Answers (1)

Marcovecchio
Marcovecchio

Reputation: 1332

Yes, $data is a multidimensional array. As Rizier123 told you, do a print_r($data), and in the browser, use the "View page source" command to see the whole hierarchy correctly indented.

If you need more info on each element (like the type), use var_dump($data).

If you are familiar with C++, you may be concerned about how it is allocated, how many dimensions it does have and so on. However, it's totally dynamic. You can create new elements and dimensions just by setting values, like this:

$data['attending_events'][$i]['tickets'][$j][1]['another dimension']['yet another one'] = 10;

Upvotes: 1

Related Questions