2013-10-19 76 views
-2

不知道如何解決這個錯誤注意:未定義偏移:使用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是否真的存在 –

回答

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皇帝 –