Putting into table from a complicated array using php -


simplexmlelement object (     [@attributes] => array         (             [version] => 2.0         )      [channel] => simplexmlelement object         (             [title] => yahoo!ニュース・トピックス - トップ             [link] => http://news.yahoo.co.jp/             [description] => aa             [language] => ja             [pubdate] => mon, 17 aug 2015 10:20:57 +0900             [item] => array                 (                     [0] => simplexmlelement object                         (                             [title] => aa                             [link] => aa                             [pubdate] => aa                             [enclosure] => simplexmlelement object                                 (                                     [@attributes] => array                                         (                                             [length] => 133                                             [url] => http://i.yimg.jp/images/icon/photo.gif                                             [type] => image/gif                                         )                                      [0] =>                                   )                              [guid] => yahoo/news/topics/6170952                         )                      [1] => simplexmlelement object                         (                             [title] => bb                             [link] => bb                             [pubdate] => bb                             [enclosure] => simplexmlelement object                                 (                                     [@attributes] => array                                         (                                             [length] => 133                                             [url] => http://i.yimg.jp/images/icon/photo.gif                                             [type] => image/gif                                         )                                      [0] =>                                   )                              [guid] => yahoo/news/topics/6170951                         ) 

i've got array confusing me beginner. want put title, link , pubdate 0=> simplexmlelement object , 1 => simplexmlelement object has aa , bb in them table pulled mysql.

my table goes like:

 title  pubdate  link 

and want put 'aa' , 'bb' under each of titles in table.

this have tried:

    foreach($con $key => $val){     while($key == title){         $title['title'] = $val;     }     return $title['title']; } 

what trying label keys , values $key , $val, , when $key = title, wanted put titles 1 array, unfortunately did not work.

assuming $xmlstructure structure posted above, code should like:

$items = $xmlstructure->channel->item; $table = []; foreach ($items $item) {     $table[] = [         'title' => $item->title,         'pubdate' => $item->pubdate,         'link' => $item->link;     ]; } 

at end of this, $table array contain array of entities, each containing 3 fields.

then, constructing html table (or table of type) should straightforward.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -