Delete element from array in PHP
You want to delete an element fom an array?
I propose to you this cimple soultion found in php.net
This functions deletes the given element from a one dimesion array.
Parameters:
$array: Array from where we will delete the element.
$deleteIt: The value we want to delete form the array.
$useOldKeys: If the value is false it would re do the index (From 0, 1, …)
If it is true it will preserve the index
Returns true if deleted, false if not found.
function deleteFromArray(&$array, $deleteIt, $useOldKeys = FALSE) { $key = array_search($deleteIt,$array,TRUE); if($key === FALSE) return FALSE; unset($array[$key]); if(!$useOldKeys) $array = array_values($array); return TRUE; }
Normally I don’t say where are the source codes since I do them or I have them since long time a go or I modify them. In this case is C&P.
I hope this is useful as it is for me.
Related Posts- Cache Class for PHP
- Open Classifieds 1.6.4 released
- Add PDF files inside other PDF in PHP
- phpMyDB - Data base class for MySql
- passGenerator - Random passwords for PHP
- Review of WordPress Plugin Development
- Tying the Classic Salmon Fly: A Modern Approach to Traditional Techniques
- Using Subdomains To Bypass Googles Sandbox
Help sharing and Flatter me ;)
