removing an array element
| From: | Erik Price | Date: | Fri, 11 Jan 2002 17:21:34 +0000 |
| Subject: | removing an array element | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-80213@lists.php.net to get a copy of this message | ||
A quick question:
what function is used to remove an array element from an array? Like array_pop(), except one by which I can refer to the element by its associative index rather than just the last element of the array.
For more detail with what I'm doing, I have two versions of a <select> listbox -- one that includes an <option> with selected="yes" (if the user is calling this page from submitting a form). The other version is for users who are NOT calling this page from submitting a form, i.e. for the first time.
I would like, in the first version (if ($formfilled)), to REMOVE the element $temprow['div_name'] from the array $temprow so that it doesn't appear a second time (in the WHILE loop), since it has already been echoed above the WHILE loop.
Is this even possible?
$home_div_id = $myrow['home_div_id']; // (from another SQL query
$div_name = $myrow['div_name']; // earlier in the script)$tempsql = "SELECT divisions.div_name, divisions.div_id
FROM divisions";$tempresult = mysql_query($tempsql, $db); $temprow = mysql_fetch_array($tempresult);
if ($formfilled) { // if this page is called with
// the form fields filled, grab
// $home_div_id and make it
// selected="yes"
echo "<select name=\"home_div_id\">\n";
echo "<option value=\"$home_div_id\" selected=\"yes\">$div_name</option>\n";
while ($temprow = mysql_fetch_array($tempresult)) {
echo "<option value=\"" . $temprow['div_id']
. "\">" . $temprow['div_name'] . "</option>\n";
}
echo "</select>\n";
} else { // if this page is called with
// blank form fields, same thing
// except no "selected" attribute
echo "<select name=\"home_div_id\">\n";
while ($temprow = mysql_fetch_array($tempresult)) {
echo "<option value=\"" . $temprow['div_id']
. "\">" . $temprow['div_name'] . "</option>\n";
}
echo "</select>\n";
}