eRott Posted April 3, 2008 Share Posted April 3, 2008 Okay, I have having a bit of trouble. I have an array contain 6 strings of numbers. I want to randomly pick one of these strings of numbers and output that chosen string. My problem is, it does not output the string, it will output a single number. What am I doing wrong? $folders = array("150593", "234156", "326514", "463152", "523574", "642552"); $folder = array_rand($folders, 1); $target = "path/".$folder; Take care. Link to comment https://forums.phpfreaks.com/topic/99401-solved-arrays-choose-random-element/ Share on other sites More sharing options...
craygo Posted April 3, 2008 Share Posted April 3, 2008 it is because array_rand returns the key not the value $folders = array("150593", "234156", "326514", "463152", "523574", "642552"); $i = array_rand($folders, 1); $target = "path/".$folders[$i]; Try that Ray Link to comment https://forums.phpfreaks.com/topic/99401-solved-arrays-choose-random-element/#findComment-508633 Share on other sites More sharing options...
eRott Posted April 3, 2008 Author Share Posted April 3, 2008 Worked. Thank you. Take care. Link to comment https://forums.phpfreaks.com/topic/99401-solved-arrays-choose-random-element/#findComment-508678 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.