Jump to content

New to PHP, need help!


awow

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.