seedg
seedg

Reputation: 21935

How can I parse the following Array?

I have this array which gets the last table from a database. However the index contains an object and not just a string.

I need to implement some string manipulation from below to get only the part table15

Array
(
    [0] => stdClass Object
    (
        [table_name] => table15
        [create_time] => 2009-11-24 13:10:04
    )

)

Any suggestions?

EDIT:

I am using ExtJs and I am a bit confused. This array is being generated from the following PDO code:

$sql  = "SELECT table_name, create_time FROM information_schema.TABLES WHERE table_schema = 'database_name' ORDER BY CREATE_TIME desc LIMIT 1";

$ostmt = $this->odb->query($sql);

return $ostmt->fetchAll(PDO::FETCH_OBJ);

This returns the array printed above. I don't know the name of the array since it is being generated like this...

Any other ideas?

Many thanks.

Upvotes: 0

Views: 144

Answers (3)

seedg
seedg

Reputation: 21935

Ok I stored the code

$ostmt->fetchAll(PDO::FETCH_OBJ) into an array variable and I gave it a name. Then I was able to manipulate it.

Thanks for the help :)

Upvotes: 0

Sabeen Malik
Sabeen Malik

Reputation: 10880

shouldnt this work?

$str = $array[0]->table_name;

Updated: As you mentioned it is being returned from the function, so i am guessing somewhere you are doing print_r(); whatever you are putting inside the print_r is your array.

Upvotes: 4

Yacoby
Yacoby

Reputation: 55445

use the -> operator.

$array[0]->table_name; //returns table15

See this question as to what stdClass is

Upvotes: 8

Related Questions