WNR Design
WNR Design

Reputation: 105

How to echo stdClass Object Title

What I want is echo the title only.

The below command is printed by the following trigger:

print_r($results);

Array ( 
   [0] => stdClass Object ( [title] => Title A [catid] => 1 ) 
   [1] => stdClass Object ( [title] => Title B [catid] => 1 ) 
) 

How can I echo just Title A

Kind regards!

Upvotes: 4

Views: 20237

Answers (4)

khawar javaid
khawar javaid

Reputation: 11

stdClass Object
(
    [0] => Array
        (
            [liquid_id] => 1
            [liquid_name] => lfts
            [amount_per_bottle] => 30
            [qty_used_per_test] => 10
            [location_id] => 1
            [liq_req_per_test] => 3
            [no_of_test_performed] => 0
            [labtest_names] => Absolute Eosinophil count
Bla bla

            [labtest_id] => 1,3,
        )

    [1] => Array
        (
            [liquid_id] => 2
            [liquid_name] => sgpt
            [amount_per_bottle] => 50
            [qty_used_per_test] => 5
            [location_id] => 1
            [liq_req_per_test] => 10
            [no_of_test_performed] => 0
            [labtest_names] => Absolute Eosinophil count
Bla bla

            [labtest_id] => 1,3,
        )

)

Upvotes: 0

Willem Ellis
Willem Ellis

Reputation: 5026

$results = Array ( 
   [0] => stdClass Object ( [title] => Title A [catid] => 1 ) 
   [1] => stdClass Object ( [title] => Title B [catid] => 1 ) 
);

$str = "";

foreach($arr as $item) {
    $result .= $item->title . "\n";
}

print $str;

Something like that?

Upvotes: 0

DiverseAndRemote.com
DiverseAndRemote.com

Reputation: 19888

To print just the names you could do:

foreach($results as $result){
    echo($result->title);
}

Upvotes: 3

Marc B
Marc B

Reputation: 360922

It's just an array of objects, so...

$results[0]->title

Upvotes: 10

Related Questions