[thelist] PHP: Associative Arrays
Michael Mell
mike at nthwave.net
Fri Jun 28 16:21:01 CDT 2002
if (isset($people['Joe'])) {
// you know Joe exists
}
http://www.php.net/manual/en/function.isset.php
if (array_key_exists($people, 'Joe') {
// you know Joe exists
}
http://www.php.net/manual/en/function.array-key-exists.php
as for the one before and the one after, etc.
see array_keys() http://www.php.net/manual/en/function.array-keys.php
and range() http://www.php.net/manual/en/function.range.php
and foreach http://www.php.net/manual/en/control-structures.foreach.php
m
Donald Noble wrote:
> Hi evolters,
>
> If I have an array set up as follows:
>
> $people = array(
> "Joe" => array ( "sname" => "Blogs", "age" => "32", "hates" =>
> "bananas"),
> "Mick" => array ( "sname" => "Mouse", "age" => "4", "hates" =>
> "cats"),
> "Dave" => array ( "sname" => "Brown", "age" => "22", "hates" =>
> "me")
> );
>
> how (if possible) can I check if there is an entry for Joe? ie I would
> like to use something similar to if(in_array("Joe"),$people)...
>
> the other question I have is, is there any way to easily get the
> previous and next entries in such an array?
>
> Cheers :Donald
>
> --
> http://www.AccessibleComputers.co.uk
> Hardware, Software & Custom built PC Systems
>
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !
--
mike[at]nthwave.net
llemekim YahooIM
415.455.8812 voice
419.735.1167 fax
More information about the thelist
mailing list