Ask a Question related to PHP Notes, Design and Development.
-
stone@php.net #1
note 30881 modified in function.unset by stone
How to delete from an array.
Answer to [oseibert at haba-ag dot de].
Unset() completly deletes an entry from the array. If you want the array numeric keys follow in a natural order you can use array_values() also.
function deleteKey($array, $keyname, $value)
{
end($array);
$last = key($array);
for($i=0; $i<=$last; $i++)
{
if($array[$i][$keyname] == $value)
{
unset($array[$i]);
}
}
$newArray = array_values( $array );
return $newArray;
}
--was--
How to delete from an array.
Answer to [oseibert at haba-ag dot de].
Unset() completly deletes an entry from the array. If you want the array numeric keys follow in a natural order you can use array_values() also.
function deleteKey($array, $keyname, $value)
{
end($array);
$last = key($array);
for($i=0; $i<=$last; $i++)
{
if($array[$i][$keyname] = $value)
{
unset($array[$i]);
}
}
$newArray = array_values( $array );
return $newArray;
}
[url]http://www.php.net/manual/en/function.unset.php[/url]
stone@php.net Guest
-
note 33852 added to function.session-unset
True, i agree!True, i agree!True, i agree!True, i agree!True, i agree!True, i agree!True, i agree!True, i agree!True, i agree!True, i agree!True, i... -
note 33807 added to function.unset
I think it could be usefull for those who had problem and don't want to use session_unregister while using $_SESSION. Under PHP 4.1.2, when... -
note 33642 added to function.unset
In reply to (svbev at umail dot ru). Note that your code uses = instead of == in the if statement. ---- Manual Page --... -
note 33640 added to function.unset
is it possible to use the unset() command to remove variables from an array? for example $keywords is an array of words in a search engine i made. ... -
note 33556 rejected from function.array by stone
Note Submitter: nchhieu@yahoo.com ---- hi every body ;o) I don't know to use an array , Please help me. In my case : $arr = array(...



Reply With Quote

