tags:

views:

46

answers:

2

i got this array from an database...how to get the exact value attribute......

Array
(
    [0] => TRowResult Object
        (
            [row] => tests
            [columns] => Array
                (
                    [a21ha:link_0] => TCell Object
                        (
                            [value] =>testsample
                            [timestamp] => 1265010584060
                        )

                    [a21ha:link_1] => TCell Object
                        (
                            [value] => example
                            [timestamp] => 1265092697040
                        )

                )

        )

how to get the [value] alone in php

+3  A: 
print $myArray[0]->columns['a21ha:link_0']->value;

This would give you the first. To get all, you'd have to loop through the contents.

foreach ($myArray[0]->columns as $column) {
  print $column->value;
}
Jonathan Sampson
Isn’t it `$array[0]->columns['a21ha:link_0']->value`?
Gumbo
@Gumbo: I'm not able to test right now, so I'll just take your word for it. I was certain that with `columns` being an array, I could access its first item via index.
Jonathan Sampson
+1  A: 

Supposed your array called $array:

foreach($array as $arridx => $rowobj){
    foreach($rowobj->columns as $cellid => $rowcell){
        echo $rowcell->value;
    }
}
silent
No need to do `as $arridx => $rowobj`, `as $rowobj` is sufficient, but nevertheless correct.
Felix Kling
yeah, it's just maybe he/she want to know the key index.
silent