views:

73

answers:

3

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.

+8  A: 

use the -> operator.

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

See this question as to what stdClass is

Yacoby
+4  A: 

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.

Sabeen Malik
A: 

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 :)

Chris
great .. so just accept an answer :) .. also next time , you can use comments against each answer to communicate with others, rather than posting an answer yourself :)
Sabeen Malik