Foros del Web » Programando para Internet » PHP »

Extraer valor de array en PHP

Estas en el tema de Extraer valor de array en PHP en el foro de PHP en Foros del Web. No me imprime el id del video que esta en la posicion 0 de: ->data->items->video->id Me da error con el siguiente codigo: Código PHP: <?php ...
  #1 (permalink)  
Antiguo 24/06/2013, 18:34
 
Fecha de Ingreso: noviembre-2012
Mensajes: 54
Antigüedad: 11 años, 5 meses
Puntos: 0
Extraer valor de array en PHP

No me imprime el id del video que esta en la posicion 0 de:
->data->items->video->id

Me da error con el siguiente codigo:


Código PHP:
<?php
 $url
="http://gdata.youtube.com/feeds/api/playlists/PLh6lmOeNKb8ln0ZkhMaxeZtiEomXBxBo2?v=2&alt=jsonc";
 
$json file_get_contents($url,0,null,null);
 
$collection json_decode($json);
 
foreach(
$collection->data->items as $index => $objecto)
{
 

  print 
$objecto->items->video->id;


}

Mi XML trae:

Código PHP:
Ver original
  1. query results:stdClass Object
  2. (
  3.     [apiVersion] => 2.1
  4.     [data] => stdClass Object
  5.         (
  6.             [id] => PLh6lmOeNKb8ln0ZkhMaxeZtiEomXBxBo2
  7.             [author] => TiranosTembladTV
  8.             [title] => Tiranos Temblad
  9.             [description] => Resumen semanal
  10.             [thumbnail] => stdClass Object
  11.                 (
  12.                     [sqDefault] => http://i.ytimg.com/vi/w5RVk9meVY0/default.jpg
  13.                     [hqDefault] => http://i.ytimg.com/vi/w5RVk9meVY0/hqdefault.jpg
  14.                 )
  15.  
  16.             [content] => stdClass Object
  17.                 (
  18.                     [5] => http://www.youtube.com/p/PLh6lmOeNKb8ln0ZkhMaxeZtiEomXBxBo2
  19.                 )
  20.  
  21.             [totalItems] => 24
  22.             [startIndex] => 1
  23.             [itemsPerPage] => 25
  24.             [items] => Array
  25.                 (
  26.                     [0] => stdClass Object
  27.                         (
  28.                             [id] => PL-MH9kz8C45WG0njbSUM9UId4rLzxN7TzxrrG22FJkmU
  29.                             [position] => 1
  30.                             [author] => TiranosTembladTV
  31.                             [video] => stdClass Object
  32.                                 (
  33.                                     [id] => KljrB6wTqfQ
  34.                                     [uploaded] => 2013-06-24T02:59:59.000Z
  35.                                     [updated] => 2013-06-24T03:53:09.000Z
  36.                                     [uploader] => tiranostembladtv
  37.                                     [category] => Entertainment
  38.                                     [title] => Tiranos Temblad 24 - Resumen de acontecimientos Uruguayos - 16/06/13 al 22/06/13
  39.                                     [description] => Como todos los lunes, un nuevo capÃ*tulo del único resumen semanal de acontecimientos del Uruguay
  40. https://www.facebook.com/TiranosTembladOficial
  41. twitter:@Tiranos_Temblad
  42. http://www.monaco.com.uy/
  43.                                     [thumbnail] => stdClass Object
  44.                                         (
  45.                                             [sqDefault] => http://i1.ytimg.com/vi/KljrB6wTqfQ/default.jpg
  46.                                             [hqDefault] => http://i1.ytimg.com/vi/KljrB6wTqfQ/hqdefault.jpg
  47.                                         )
  48.  
  49.                                     [player] => stdClass Object
  50.                                         (
  51.                                             [default] => http://www.youtube.com/watch?v=KljrB6wTqfQ&feature=youtube_gdata_player
  52.                                             [mobile] => http://m.youtube.com/details?v=KljrB6wTqfQ
  53.                                         )
  54.  
  55.                                     [content] => stdClass Object
  56.                                         (
  57.                                             [5] => http://www.youtube.com/v/KljrB6wTqfQ?version=3&f=playlists&app=youtube_gdata
  58.                                             [1] => rtsp://v6.cache7.c.youtube.com/CiULENy73wIaHAn0qROsB-tYKhMYDSANFEgGUglwbGF5bGlzdHMM/0/0/0/video.3gp
  59.                                             [6] => rtsp://v6.cache7.c.youtube.com/CiULENy73wIaHAn0qROsB-tYKhMYESARFEgGUglwbGF5bGlzdHMM/0/0/0/video.3gp
  60.                                         )
  61.  
  62.                                     [duration] => 481
  63.                                     [aspectRatio] => widescreen
  64.                                     [rating] => 5
  65.                                     [likeCount] => 77
  66.                                     [ratingCount] => 77
  67.                                     [viewCount] => 301
  68.                                     [favoriteCount] => 0
  69.                                     [commentCount] => 19
  70.                                     [accessControl] => stdClass Object
  71.                                         (
  72.                                             [comment] => allowed
  73.                                             [commentVote] => allowed
  74.                                             [videoRespond] => moderated
  75.                                             [rate] => allowed
  76.                                             [embed] => allowed[list] => allowed
  77.                                             [autoPlay] => allowed
  78.                                             [syndicate] => allowed
  79.                                         )
  80.  
  81.                                 )
  82.  
  83.                         )
  84.  
  85.                     [1] => stdClass Object
  86.                         (
  87.                             [id] => PL-MH9kz8C45WG0njbSUM9UJXnI79luF7GH9sFccpUyA0
  88.                             [position] => 2
  89.                             [author] => TiranosTembladTV
  90.                             [video] => stdClass Object
  91.                                 (
  92.                                     [id] => OPcPSJP-0ck
  93.                                     [uploaded] => 2013-06-17T03:11:35.000Z
  94.                                     [updated] => 2013-06-24T03:44:42.000Z
  95.                                     [uploader] => tiranostembladtv
  96.                                     [category] => Entertainment
  97.                                     [title] => TiranosTemblad 23 - Resumen de acontecimientos Uruguayos - 09/06/13 al 15/06/13
  98.                                     [description] => Como todos los lunes, un nuevo capÃ*tulo del único resumen semanal de acontecimientos del Uruguay
  99. https://www.facebook.com/TiranosTembladOficial
  100. twitter:@Tiranos_Temblad
  101. http://www.monaco.com.uy/
  102.                                     [thumbnail] => stdClass Object
  103.                                         (
  104.                                             [sqDefault] => http://i1.ytimg.com/vi/OPcPSJP-0ck/default.jpg
  105.                                             [hqDefault] => http://i1.ytimg.com/vi/OPcPSJP-0ck/hqdefault.jpg
  106.                                         )
  107.  
  108.                                     [player] => stdClass Object
  109.                                         (
  110.                                             [default] => http://www.youtube.com/watch?v=OPcPSJP-0ck&feature=youtube_gdata_player
  111.                                             [mobile] => http://m.youtube.com/details?v=OPcPSJP-0ck
  112.                                         )
  113.  
  114.                                     [content] => stdClass Object
  115.                                         (
  116.                                             [5] => http://www.youtube.com/v/OPcPSJP-0ck?version=3&f=playlists&app=youtube_gdata
  117.                                             [1] => rtsp://v7.cache5.c.youtube.com/CiULENy73wIaHAnJ0f6TSA_3OBMYDSANFEgGUglwbGF5bGlzdHMM/0/0/0/video.3gp
  118.                                             [6] => rtsp://v7.cache5.c.youtube.com/CiULENy73wIaHAnJ0f6TSA_3OBMYESARFEgGUglwbGF5bGlzdHMM/0/0/0/video.3gp
  119.                                         )
  120.  
  121.                                     [duration] => 459
  122.                                     [aspectRatio] => widescreen
  123.                                     [rating] => 4.990172
  124.                                     [likeCount] => 406
  125.                                     [ratingCount] => 407
  126.                                     [viewCount] => 15805
  127.                                     [favoriteCount] => 0
  128.                                     [commentCount] => 93
  129.                                     [accessControl] => stdClass Object
  130.                                         (
  131.                                             [comment] => allowed
  132.                                             [commentVote] => allowed
  133.                                             [videoRespond] => moderated
  134.                                             [rate] => allowed
  135.                                             [embed] => allowed[list] => allowed
  136.                                             [autoPlay] => allowed
  137.                                             [syndicate] => allowed
  138.                                         )
  139.  
  140.                                 )
  141.  
  142.                         )
  #2 (permalink)  
Antiguo 24/06/2013, 18:42
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Extraer valor de array en PHP

Temas duplicados:

http://www.forosdelweb.com/f18/php-s...datos-1059021/
http://www.forosdelweb.com/f18/php-p...bjetc-1059761/
http://www.forosdelweb.com/f18/stdcl...lores-1059297/
http://www.forosdelweb.com/f18/php-s...datos-1059021/

self, por favor consulta las normas del foro, no está permitido que andes duplicando temas por doquier.

Respeta las normas y aprende a usar el foro, evítanos la molestia de sancionarte.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 24/06/2013, 19:03
 
Fecha de Ingreso: noviembre-2012
Mensajes: 54
Antigüedad: 11 años, 5 meses
Puntos: 0
Respuesta: Extraer valor de array en PHP

gracias como hago para borrar los demas temas y dejar este??????
  #4 (permalink)  
Antiguo 26/06/2013, 22:04
Avatar de alvidales  
Fecha de Ingreso: febrero-2012
Mensajes: 108
Antigüedad: 12 años, 2 meses
Puntos: 11
Respuesta: Extraer valor de array en PHP

Código:
foreach($collection->data->items as $index => $objecto)
{
     print $objecto[$index]->video->id;
}
__________________
Hasta que el hombre no es nada, Dios no puede hacer nada con el.

Última edición por alvidales; 26/06/2013 a las 23:30

Etiquetas: valor
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:56.