foreach ($video_filer['items'] as $video) {
if (isset($video['id'])) {
$date = new DateTime($video['snippet']['publishedAt']);
$time = covtime($video['contentDetails']['duration']);
//convert the date
$video_date = date_format($date, 'd/m/y');
//create the video list details
$data[] = array(
"thumbnail" => $video['snippet']['thumbnails']['medium']['url'],
"title" => htmlspecialchars($video['snippet']['title'], ENT_QUOTES, 'UTF-8'),
"title_short" => short_text_out(htmlspecialchars($video['snippet']['title'], ENT_QUOTES, 'UTF-8'), 4),
"username" => $video['snippet']['channelTitle'],
"profile" => "https://www.youtube.com/channel/" . $video['snippet']['channelId'],
"views" => (isset($video['statistics']['viewCount'])) ? $video['statistics']['viewCount'] : '',
"date" => $video_date,
"time" => $time,
"more" => 'https://www.youtube.com/watch?v=' . $video['id'],
"embed_url" => 'http://www.youtube.com/embed/' . $video['id'] . '?autoplay=1',
);
}
}
1
2 respuestas
1
podes usar json_encode
y json_decode
algo asi:
<?php
/* silly random data generator */
function randData($maxChars=50, $intVals=false){
$i = rand(0,$maxChars);
$t = substr(str_repeat(md5(microtime()),$maxChars%26),rand(0,26),$maxChars);
return $intVals?$i:$t;
}
$fileArray= array(
"Category"=>randData(16),
"Key"=>randData(32),
"Value"=>randData(1000,true),
"Description"=>randData(120)
);
/* Array como Object */
$fileObjeto = json_decode(json_encode($fileArray, JSON_FORCE_OBJECT));
echo "<pre>".PHP_EOL;
var_dump($fileArray);
var_dump($fileObjeto);
echo "</pre>".PHP_EOL;
1
Otra manera de conseguirlo es forzando la conversión a tipo object
la sintaxis sería la siguiente:
$Objeto = (object)$Array;
Aquí más información soblre la mannipulación de tipos en PHP
Dejo un ejemplo de uso:
<?php
$Array = array(
"key1" => 'value1',
"key2" => 'value2',
"key3" => 'value3',
"key4" => 'value4',
);
$Objeto = (object)$Array;
echo "<pre>" . PHP_EOL;
print_r($Array);
print_r($Objeto);
echo "</pre>" . PHP_EOL;