0

I want to echo CATEGORIA Under Booking_meta but nested valued I am not able to echo, here is the print_r results"

I am able to access level 1 array like:

echo $EM_Booking-> booking_id;

but nested valued inside [registration] and [booking] array I didn't able to echo results, I am little weaker when playing with arrays :)

EM_Booking Object
(
[booking_id] => 13
[event_id] => 31
[person_id] => 0
[booking_price] => 0.0000
[booking_spaces] => 1
[booking_comment] => 
[booking_status] => 1
[booking_tax_rate] => 0
[booking_taxes] => 
[booking_meta] => Array
    (
        [registration] => Array
            (
                [user_name] => rb
                [first_name] => rb
                [last_name] => 
                [dbem_email] => [email protected]
                [user_email] => [email protected]
                [dbem_phone] => 33446667678
                [dbem_societa] => ttf
                [dbem_ente] => FCI (Federazione Ciclistica Italiana)
                [dbem_cod_societa] => 6666
                [dbem_tessera_n_] => 3344
            )

        [booking] => Array
            (
                [categoria] => M2 35-39 (nati 1978/1982)
                [dbem_tesseramento] => 
            )

    ) 
1
  • What code did you use to try to access the array values? Commented Jul 23, 2017 at 14:24

2 Answers 2

1

What you have is Arrays inside Object, so what you can do easily is as follows

// Here is how to access array

// This is your reg array
$reg_array =  $EM_Booking->booking_meta['registration'];

// This is your booking array
$booking_array =  $EM_Booking->booking_meta['booking'];

// Uncomment below if you wanna see array 
// print_r($reg_array);
// print_r($booking_array);

// either through array
echo $booking_array['categoria'];

// Or directly
echo $EM_Booking->booking_meta['booking']['categoria']

OR else

$myobject = json_decode( json_encode($EM_Booking) );

// and then
echo $myobject->booking_meta->registration->user_name;

echo $myobject->booking_meta->booking->categoria;
Sign up to request clarification or add additional context in comments.

Comments

1

To access data inside [registration] and [booking], you need to write your lines like that:

echo $EM_Booking->booking_meta['registration']['user_name'];
echo $EM_Booking->booking_meta['booking']['categoria'];

You cannot use something like:

$EM_Booking->booking_meta->registration->user_name

Because the data stored inside [booking_meta] and [booking] are not Objects. If you look at the dumped data, they are Arrays, so the way to access them is different.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.