A sample how to unset array elements from an array result coming from a mysql request. In this sample it is checking if a file exists and removes the row from the array if it not exists.
<?php
$db->set_query("select * from documents where document_in_user = 0"); $documents = $db->result_to_array($db->get_result()); foreach ($documents as $key => $row) { $file = "uploads/".rawurldecode($row['document_name']);
if ( file_exists ( $file ) == FALSE ) {
unset($documents[$key]); }
}
$documents = array_values($documents); ?>
variables:
mysql table = documents,
array = $documents
array key (index) = $key
array row (record sort of speak) = $row
explanation:
1.
it gets the array from the table (mysql)
2.
foreach goes through the array $documents
3.
unset if record does not exist
4.
the array_values($documents) reindexes the $documents array, for otherwise you might end up in trouble when your process will start expecting an array starting with key ($key) 0 (zero).