0

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.

seedg
  • 20,820
  • 10
  • 37
  • 59

3 Answers3

8

use the -> operator.

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

See this question as to what stdClass is

Community
  • 1
  • 1
Yacoby
  • 51,022
  • 12
  • 106
  • 116
4

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
  • 10,650
  • 4
  • 31
  • 49
0

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

seedg
  • 20,820
  • 10
  • 37
  • 59
  • 1
    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 Nov 27 '09 at 13:53