php array to radio button
Question by user2128593
i want to create a radio button labeled with the values of my array. all i can do is to print them all. what can i use to access my array (dynamic-array) besides indexes since i will not know the order and number of files inside my languages directory? Thanks!
input
english.xml,mandarin.xml,french.xml
these files is saved at languages and i will use the file names as labels in my radio button form.
$files = glob("languages/*.xml");
foreach($files as $file){
$file = substr($file, 10); //removes "languages/"
$file = substr_replace($file, "", -4); //removes ".xml"
?>
<p><?=$file?></p> // prints out the filename
<?}?>
output
<form action="">
<input type="radio" name="lang" value="english">english
<input type="radio" name="lang" value="mandarin">mandarin
<input type="radio" name="lang" value="french">french
</form>
sorry for my bad english i hope i explained it well.
Answer by Starx
You can access the key of the array using foreach too. Like this:
foreach($files as $key => $value) {
//....
}