Quick questions about manipulating arrays
Posted: Wed Jun 07, 2006 6:11 pm
I really, normally wouldn't post something like this, but.. It's for work and I need it now.
Why isn't this working how I intend it to?
I want it to clear the empty keys out of the POST array. Is it because it's the post array? Is unset not the proper function here? Or am I simply an idiot?
Please help
Why isn't this working how I intend it to?
I want it to clear the empty keys out of the POST array. Is it because it's the post array? Is unset not the proper function here? Or am I simply an idiot?
Please help
Code: Select all
<?php
if ($_POST)
{
echo '<h2>before:</h2>';
echo "<pre>";
print_r($_POST);
echo "</pre>";
function parse_array($item)
{
if (empty($item) != FALSE)
{
unset($item);
}
}
array_walk($_POST, 'parse_array');
echo '<h2>after:</h2>';
echo "<pre>";
print_r($_POST);
echo "</pre>";
}
else
{
?>
<form action="test.php" method="post">
<?php
for ($i = 0; $i < 15; $i++)
{
echo "<input type=\"input\" name=\"qty_".$i."\" size=\"5\" /><br />";
}
?>
<input type="submit" name="submit" value="submit" />
</form>
<?php
}
?>