注意:未定义偏移:使用0阵列中

问题描述:

不知道如何解决这个错误注意:未定义偏移:使用0阵列中

注意:未定义偏移量:0在C:\ XAMPP \ htdocs中\ streams.php上线50 说明:未定义偏移:0在C:\ XAMPP \ htdocs中\ streams.php上线53 注意:未定义偏移量:0在C:\ XAMPP \ htdocs中\ streams.php线路54上

代码其指:

<?php 

$members = array("hawkmyg"); 

$userGrab = "http://api.justin.tv/api/stream/list.json?channel="; 

$checkedOnline = array(); 

foreach($members as $i =>$value){ 
    $userGrab .= ","; 
    $userGrab .= $value; 
} 
unset($value); 

//grabs the channel data from twitch.tv streams 
$json_file = file_get_contents($userGrab, 0, null, null); 
$json_array = json_decode($json_file, true); 

//get's member names from stream url's and checks for online members 
foreach($members as $i =>$value){ 
    $title = $json_array[$i]['channel']['channel_url']; 
    $array = explode('/', $title); 
    $member = end($array); 
    $viewer = $json_array[$i] ['stream_count']; 
    onlinecheck($member, $viewer); 
    $checkedOnline[] = signin($member); 
} 

无法确定如何修复

+0

没有看到您的输入数据('$ members'和'$ json_array'),没有人可以帮助您。但是我希望在第一次循环期间'$ i == 0'和'$ json_array'没有'0'元素。 – ThiefMaster

+0

使用标准的调试工具'var_dump'或'print_r' –

+0

uset print_r来查看偏移量0是否真的存在 –

当调用具有特定索引的数组元素时,会发生未定义偏移量的通知,例如echo $array[$index],但索引未在数组内定义。

在您的代码中,数组$members有一个元素(索引0)。所以我们通过foreach循环准确地执行一次。
您在致电$json_array[$i]['channel']['channel_url']其中$i = 0,但$json_array[0]不存在。

您应该检查$json_array的内容使用print_r()var_dump()

我自己测试了脚本,当我读到链接http://api.justin.tv/api/stream/list.json?channel=,hawkmyg的内容时,它返回了一个空的JSON数组。频道'hawkmyg'不存在。
我试过频道'hatoyatv',它刚刚工作。

+0

我知道现在是什么,我没有justin.tv帐户只有twitch.tv和api是不同的ty皇帝 –