note 70866 deleted from ref.array by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: zspencer at zacharyspencer dot com 

----

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;
	
}
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.