Making changes to session array

Hello,
I have a text area which when filled out, each line gets inserted into a session array.
I am printing out the array and i want the user to be able to delete any row or name from the array.
Also a button to clear out the entire array would be great.

How to I delete a specific value in an array,
Here is what I have:
Form:

form method="POST" action="<?php echo $editFormAction; ?>" name="form1" class="form-horizontal">
 <textarea class="field span10" rows="24" id="studentarray" name="studentarray" placeholder="Enter Student Names (one per line)"></textarea>
 <input type="hidden" name="InsertArray" value="form1">
 <input type="submit" value="Add" class="btn btn-primary">

PHP to create array

if ((isset($_POST["InsertArray"])) && ($_POST["InsertArray"] == "form1")) {
$studentnames=array();
$_SESSION['studentnames'] = $studentnames;
$textarea_value1 = $_POST['studentarray'];
$lines1 = explode("\
", $textarea_value1);
foreach ($lines1 as $line1){
$_SESSION['students'][] = $line1;
}
}

Echoing Array

<table class="table table-condensed table-bordered table-striped">
			<thead>
			<tr>
			<th> Student Name</th><th></th>
			</tr>
			
			</thead>
			<tbody>
			<?php $students = $_SESSION['students'];
			foreach ($students as $studentname) {
			echo "<tr><td>" . $studentname ."</td><td>X</td></tr>";
			}
			?></tr></table>
            </div>
			<!--/span-->

When loading the array I would assign an index number to each element. Then when displaying them add a checkbox with this index to delete it, you use the value of the checkbox to unset the array element with that index.

Any way you can point me to an example? I am not an expert in PHP.

so far I have added an index and a checkbox. Just need help deleting the element from array


$students = $_SESSION['students'];
			$i = 0;
			foreach ($students as $studentname) {
			$count = count($_SESSION['students']);
			echo '<tr><td>' . $studentname . '' . $i .'</td><td>  <input type="checkbox" name="delstudent" id="delstudt<?php echo $i;?>" value="<?php echo $i;?>"></td></tr>';
			$i++;
			}
			?>

Remove the $I from the td with the student name and add brackets to the name attribute of the checkbox to handle multiple checks. Use the quotes better for a cleaner line.
Like this:



echo "<tr><td>$studentname</td><td><input type='checkbox' name='delstudent[]' value='$i'></td></tr>";


Now when you retrieve the POST[‘delstudent’] that assigned var will be an array. Loop thru it collecting the value of an element and using it to get the corresponding student name and unset it (unset($_SESSION[$i]).
Or you could use the actual name by assigning that to the checkbox value instead of a counter.

More importantly, where do the names come from? Are they in a table that loaded the session array to begin with? Then you have to do a delete query to drop them from the table.