I am new to PHP. Hope someone will help me.

I used following code to get the array of items from "mylist.txt" file. When I run the file, it displays all the list names with a check box.(that's what I wanted) but, When the user tick one box and submit the form I need user's selected list name appear on my "processfile.php" But instead, I am getting " You have Selected array. and 1 name selected.

following are my requirements for this file-

1. I need to get data from a text file. (mylist.txt)

2. When the user select one item, I need it to be displayed on a separate
file. (Ex. you have selected "name of the item")

3. When everytime I update the list on my text file (add items or delete
items) I need them to be updated on other file with the check box too.

4. If user select more than one item, I need to display error message. (Ex.
"Please select one") something.

5. If user select none again I need error message ("something")

6. When user correctly select only one item, then another message.
(Ex. thank you something) and it shoud write to other file

I wrote following codes and still I can not get this correct. Can someone please help me.

PHP Code:

 $listName 
file("mylist.txt");

            foreach (
$listName as $name) {
                print 
"<input type=\"checkbox\" name=\"listName[]\" value=\"$name\" />";
                print 
"$name <br/>";
            }
            
?>
            
            <input type="submit" name="submit" value="submit"/>
        </form> 
and on another file ""processfile.php" I wrote following code.

PHP Code:

<?php
        
        
print "You have Selected .{$_POST['listName']}<br/>";

        print 
"<br/>" count($_POST['listName']) . " name selected.<br/>";
        
        
$listfile fopen("userchoice.txt"'w') or die("Can not open the file");
        
fwrite($listfile$_POST['listName']);
        
fclose($listfile);
        
 
?>
Please someone help me.