Re: Arrays

From: Date: Sat, 27 Oct 2001 00:12:38 +0000
Subject: Re: Arrays
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-72533@lists.php.net to get a copy of this message
On Sat, 27 Oct 2001 01:41, Ashley M. Kirchner wrote: > In a different language I can write something that will return the > index of $section in the array, then I can use that index value to fetch > the INT afterwards: > > $array = {{"section1", 1},{"section2",4},{"section3",2}} > if (idx = ($section in list_iassoc($array, 1))) => 1 being the > first element > // idx[1] = "section#" > // idx[2] = INT > if ($page > 0 && $page =< $array[idx][2]) > > etc. Like this? #! /usr/local/bin/php -q <?php // Suck 'em in $site = array ( "section1" => 007, "section2" => 11, "section3" => 57.5, "section4" => 12, "section5" => 0.007, "section6" => 15, "section7" => 1007, "section8" => 11007, "section9" => 111007, "section10" => 1 ); // Arbitrary $page = 5; for( $i = 1; $i <= 10; $i++ ) { $section = "section".$i; if ( $page > 0 && $page <= (int)$site[$section] ) { print "The value of $section is greater than the value of \$page\n"; } else { print "The value of $section is less than the value of \$page\n"; } } ?> Cheers, BAD

« previous php.general (#72533) next »