note 85695 added to function.array-slice
| From: | s0i0m at dreamevilconcepts dot com | Date: | Fri, 12 Sep 2008 14:53:30 +0000 |
| Subject: | note 85695 added to function.array-slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144367@lists.php.net to get a copy of this message | ||
Using the varname function referenced from the array_search page, submitted by dcez at land dot ru.
I created a multi-dimensional array splice function. It's usage is like so:
$array['admin'] = array('blah1', 'blah2');
$array['voice'] = array('blah3', 'blah4');
array_cut('blah4', $array);
...Would strip blah4 from the array, no matter where the position of it was in the array ^^
Returning this...
Array ( [admin] => Array ( [0] => blah1 [1] => blah2 ) [voice] => Array ( [0] =>
blah3 ) )
Here is the code...
<?php
function varname ($var)
{
// varname function by dcez at land dot ru
return (isset($var)) ? array_search($var, $GLOBALS) : false;
}
function array_cut($needle, $haystack)
{
foreach ($haystack as $k => $v)
{
for ($i=0; $i<count($v); $i++)
if ($v[$i] === $needle)
{
return array_splice($GLOBALS[varname($haystack)][$k], $i, 1);
break; break;
}
}
?>
Check out dreamevilconcept's forum for more innovative creations!
----
Server IP: 87.124.35.190
Probable Submitter: 92.1.182.133
----
Manual Page -- http://www.php.net/manual/en/function.array-slice.php
Edit -- https://master.php.net/note/edit/85695
Del: integrated -- https://master.php.net/note/delete/85695/integrated
Del: useless -- https://master.php.net/note/delete/85695/useless
Del: bad code -- https://master.php.net/note/delete/85695/bad+code
Del: spam -- https://master.php.net/note/delete/85695/spam
Del: non-english -- https://master.php.net/note/delete/85695/non-english
Del: in docs -- https://master.php.net/note/delete/85695/in+docs
Del: other reasons-- https://master.php.net/note/delete/85695
Reject -- https://master.php.net/note/reject/85695
Search -- https://master.php.net/manage/user-notes.php