I have a form that allows a user to add and delete objects from an array. The deleting process works by taking the array and dumping all the contents into a dropdown list the user can select what they want to delete from.
<?php
session_start(1);
if (isset($_SESSION['array'])){
$narray = $_SESSION['array'];
if ($narray != NULL){
echo "DDDD";
}
echo 'Select an object to delete: ';
echo '<select name=deleteob>';
foreach($narray as $drop){
echo'<option value="'.$drop.'">'.$drop.'</option>';
}
echo '</select>';
Whenever all of the contents are deleted, the array does not 'clear'? I'm not sure the word, it does not seem to be actually emptying. The echo 'DDDD' is to see if the array has something contained inside of it. I've also tried seeing if the array is NULL, but neither will echo anything, but the dropdown list is still being created with an empty selection. The array is being pulled from a process page by a session variable on another page. Basically array has nothing inside of it but acts like it does. Anything i am doing wrong to cause this? Sorry for bad english
Change
if ($narray != NULL) {
to:
if (!empty($narray)) {
If you delete all the elements of an array, it's still an array, and is not equal to null
.