note 70866 added to ref.array
| From: | zspencer at zacharyspencer dot com | Date: | Wed, 01 Nov 2006 14:59:33 +0000 |
| Subject: | note 70866 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119299@lists.php.net to get a copy of this message | ||
The array system is sadly lacking a "set" function... I needed one that would set the
pointer to the key that I specified.
So I wrote my own.
<?
$array=array();
$array['a']='lala';
$array['b']='blabla';
$array['c']='nono';
set($array, 'b');
echo current($array);
// outputs blabla
function set(&$array, $key)
{
reset($array);
while($current=key($array))
{
if($current==$key)
{
return true;
}
next($array);
}
return false;
}
?>
----
Server IP: 216.194.113.175
Probable Submitter: 69.41.14.248
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- https://master.php.net/note/edit/70866
Del: integrated -- https://master.php.net/note/delete/70866/integrated
Del: useless -- https://master.php.net/note/delete/70866/useless
Del: bad code -- https://master.php.net/note/delete/70866/bad+code
Del: spam -- https://master.php.net/note/delete/70866/spam
Del: non-english -- https://master.php.net/note/delete/70866/non-english
Del: in docs -- https://master.php.net/note/delete/70866/in+docs
Del: other reasons-- https://master.php.net/note/delete/70866
Reject -- https://master.php.net/note/reject/70866
Search -- https://master.php.net/manage/user-notes.php