-2

不确定如何修复此错误

注意:未定义的偏移量:第 50 行的 C:\xampp\htdocs\streams.php 中的 0 注意:未定义的偏移量:第 53 行的 C:\xampp\htdocs\streams.php 中的 0 注意:未定义的偏移量:C:\ 中的 0第 54 行的 xampp\htdocs\streams.php

代码其指的是:

<?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);
}

无法弄清楚如何修复

4

1 回答 1

0

The notice of an undefined offset occurs when one calls an array element with the specific index, for example, echo $array[$index], but the index is not defined within the array.

In your code, the array $members has one element (with index 0). So we're walking exactly one time through your foreach loop.
You're calling $json_array[$i]['channel']['channel_url'] where $i = 0, but $json_array[0] does not exist.

You should check the contents of $json_array using print_r() or var_dump().

I tested the script myself, and when I read the contents of the link http://api.justin.tv/api/stream/list.json?channel=,hawkmyg, it returned an empty JSON array. The channel 'hawkmyg' does not exist.
I tried the channel 'hatoyatv', and it just worked.

于 2013-10-19T11:38:05.833 回答