I have the following code:
$rss = simplexml_load_file( 'http://gdata.youtube.com/feeds/api/playlists/PLEA1736AA2720470C?v=2&prettyprint=true' );
foreach ( $rss->entry as $entry ) {
// get nodes in media: namespace for media information
$media = $entry->children( 'http://search.yahoo.com/mrss/' );
$thumbs = $media->group->thumbnail;
$thumb_attrs = array();
$index = 0;
// get thumbnails attributes: url | height | width
foreach ( $thumbs as $thumb ) {
foreach ( $thumb->attributes() as $attr => $value ) {
$thumb_attrs[$index][$attr] = $value;
print $attr . ': ' . $thumb_attrs[$index][$attr] . "| ";
}
$index++;
print "<br>";
}
}
The print will output:
url: http://i.ytimg.com/vi/te28_L-dO88/default.jpg| height: 90| width: 120| time: 00:00:49|
...
from the xml tags with the following format:
<media:thumbnail url='http://i.ytimg.com/vi/4l4rwvAPhfA/default.jpg' height='90' width='120' time='00:02:23.500' yt:name='default'/>
...
How can I add the attribute with namespace yt name = 'default' that I'm not getting to the array?
How can I get the closest value of all width to other value from the array? Something similar to PHP - Nearest value from an array but taking into account that my array is multidimensional.