awow Posted April 17, 2010 Share Posted April 17, 2010 Here is a code snipet from my current PHP project. randomAlbum takes in a file, and $singleRandomArtist is being set to an integer for an index reference in the foreach loop. However, I am getting this error: Notice: Undefined offset: 5 in ///Assignment 3\functions.php on line 194 I've been working on this for over an hour and a half, and am hoping someone out there can help me out!! Thanks in advance! Alex function randomAlbum() { $artists = file('resources/artists.txt'); $singleRandomArtist = getRandomInt(1, 27); foreach ($artists as $singleArtist) { $randomArtist = explode("~", $singleArtist); /*I should mention this splits artists.txt into an array of 27 items, indexing from 0-26*/ echo $randomArtist[$singleRandomArtist - 1]; /*this is line 194*/ } } function getRandomInt($min, $max) { $validRand = false; while ($validRand == false) { $random = rand($min, $max); if (($random % 3) == 0) { $validRand = true; } else; } return $random; } Link to comment https://forums.phpfreaks.com/topic/198820-new-to-php-need-help/ Share on other sites More sharing options...
Ken2k7 Posted April 17, 2010 Share Posted April 17, 2010 I don't understand. file already breaks it up by lines and it returns an array. Do you have all artists in 1 line? Link to comment https://forums.phpfreaks.com/topic/198820-new-to-php-need-help/#findComment-1043585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.