php - Retrieving value from object

865

I cant get the value out of [Create Table] because of the space.

I create the object like this...

$create_table = DB::select('SHOW CREATE TABLE '.$table_name)[0];

And this is what the object looks like...

stdClass Object
(
    [Table] => contact_monitor
    [Create Table] => CREATE TABLE `contact_monitor` (
        `contact_id` int(11) DEFAULT NULL,
        `monitor_id` int(11) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1
)

However, I can get the value out of [Table] using$create_table->Table

959

Answer

Solution:

Just use a{} curly brace to access those properties with spaces:

echo $create_table->{'Create Table'}; // this will also work on hyphenated properties as well

People are also looking for solutions to the problem: apache - PHP cURL get requesting host

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.