Jump to content

get content of array


clankill3r

Recommended Posts

i have a array calles $articles, this is a part of it:

 

Array
(
    [1335905082] => Array
        (
            [channel] => 
            [title] => SimpleXMLElement Object
                (
                    [0] => NEW PRODUCT – Blue 7-segment clock display – 0.56 digit height
                )

            [link] => SimpleXMLElement Object
                (
                    [0] => http://www.adafruit.com/blog/2012/05/01/new-product-blue-7-segment-clock-display-0-56-digit-height/
                )

            [comments] => SimpleXMLElement Object
                (
                    [0] => http://www.adafruit.com/blog/2012/05/01/new-product-blue-7-segment-clock-display-0-56-digit-height/#comments
                )

            [pubDate] => SimpleXMLElement Object
                (
                    [0] => Tue, 01 May 2012 20:44:42 +0000
                )

            [timestamp] => 1335905082
            [description] => NEW PRODUCT – Blue 7-segment clock display – 0.56 digit height. Design a clock, timer or counter into your next project using our pretty 4-digit seven-segment display. These bright crisp displays are good for adding numeric output. Besides the four 7-segments, there are decimal points on each digit and an extra wire for colon-dots in [...]
            [isPermaLink] => SimpleXMLElement Object
                (
                    [0] => false
                )

            [creator] => adafruit

 

when i use:

 

foreach($articles as $article) {
$title = $article['title'][0];
echo '<pre>';
print_r($title);
echo '</pre>';
}

 

i get stuff like:

 

SimpleXMLElement Object

(

    [0] => NEW PRODUCT – Yellow 7-segment clock display – 0.56 digit height

)

SimpleXMLElement Object

(

    [0] => NEW PRODUCT – Dual H-Bridge Motor Driver for DC or Steppers – 600mA – L293D

)

 

But i expected:

 

NEW PRODUCT – Yellow 7-segment clock display – 0.56 digit height

NEW PRODUCT – Dual H-Bridge Motor Driver for DC or Steppers – 600mA – L293D

 

what do i do wrong?

Link to comment
https://forums.phpfreaks.com/topic/261953-get-content-of-array/
Share on other sites

Why do you think it's bad?

(what's wrong is the use of "". And you're using array reference instead of object. ->

 

Edit: read too fast.

What u did converts the object to a string which is probably fine for what you're doing. It could be better.

Theres no way you read all 3 of those doc page that fast. The object one is what's important.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.