Question : How to display 15 random usernames with single quote on each username in an array?
Code :
$friendsArray = array("zac1987", "peter", "micellelimmeizheng1152013142",.....);
$randomfriends = array_rand($friendsArray, 15); //random select 15 usernames
foreach($randomfriends as $c => $friend){ //wrap each username in a single quote
$friendsArray[$c] = "'".mysql_real_escape_string($friendsArray[$c])."'";
}
$friendsArray2 = join(', ',$friendsArray);
echo $friendsArray2;
Output :
'hh', 'gg', 'ff', 'dd', 'ss', 'aa', 'oo', 'ii', 'uu', 'yy', 'tt', 'rr', 'ee', 'ww', 'qq', micellelimmeizheng1152013142, vv, bb
The problem can be seen obviously through the output. micellelimmeizheng1152013142, vv, bb are 16th, 17th and 18th entry without single quotes, they supposedly not to be shown, how to delete them?