1
<?php

$articleurl = 'http://m.tonton.com.my/webservices/article/get?uniqueid=6E619732-9501-4106-860C-  A20D0016E7F0&includeChildTypes=episode&parents=package_season%2Cpackage_content%2Cprogram&c hildren=1&sortBy=published_date&sortDirection=ASC&compact=0&cache=';
$articlecontent = file_get_contents($articleurl);
$articlejson = json_decode($articlecontent, true);
$arr = $articlejson["data"]["children"];
$max = max(array_keys($arr));
echo $max; //8 episode
for ($i=0; $i<=$max;++$i)
{
    $articleid[$i] = $articlejson['data']['children']['$i']['uniqueId'];
    $mediaid[$i] = $articlejson['data']['children']['$i']['version_viostream_id']['default'];
    $resources[$i] = 'http://m.tonton.com.my/webservices/media/getProgressiveResources?articleid='.$articleid[$i].'&mediaid='.$mediaid[$i].'&token=&cache=&manifestMode=progressive';
    print_r($resources[$i]);
}

我正在尝试查找所有可用的数组键并将可用变量插入到链接中,但是当我运行代码时,出现错误:

“未定义的索引:第 15 行 C:\xampp\htdocs\index.php 中的 $i 注意:第 16 行 C:\xampp\htdocs\index.php 中的 $i 未定义索引”

4

1 回答 1

1

您有语法错误,不是'$i',而是$i

$articleurl = 'http://m.tonton.com.my/webservices/article/get?uniqueid=6E619732-9501-4106-860C-  A20D0016E7F0&includeChildTypes=episode&parents=package_season%2Cpackage_content%2Cprogram&c hildren=1&sortBy=published_date&sortDirection=ASC&compact=0&cache=';
$articlecontent = file_get_contents($articleurl);
$articlejson = json_decode($articlecontent, true);
$arr = $articlejson["data"]["children"];
$max = max(array_keys($arr));
echo $max; //8 episode
for ($i=0; $i<=$max;++$i)
{
$articleid[$i] = $articlejson['data']['children'][$i]['uniqueId'];
$mediaid[$i] = $articlejson['data']['children'][$i]['version_viostream_id']['default'];
$resources[$i] = 'http://m.tonton.com.my/webservices/media/getProgressiveResources?articleid='.$articleid[$i].'&mediaid='.$mediaid[$i].'&token=&cache=&manifestMode=progressive';
print_r($resources[$i]);
}
于 2013-10-22T11:16:14.640 回答