Re: finding a value in an array

From: Date: Mon, 04 Nov 2002 12:26:39 +0000
Subject: Re: finding a value in an array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-122662@lists.php.net to get a copy of this message
Craig wrote: > I have a database table that holds the values of IDs in the format > 1,2,3,4,5,67,x,x,x,x,x,x > > I am using a dynamic select list menu that displays a list of items > from a 2nd table with the values set to their unique ids > eg > <option vaue =1>item 1</option> > <option vaue =2>item2</option> > <option vaue =3>item 3</option> > <option vaue =4>item 4</option> > <option vaue =5>item 5</option> > > i am trying to use an array search that will highlight the item if the > option value is in the array of the IDs, but with no luck, either all > the ids are highlighted or none at all $ids = '1,2,3,4,5,6,7'; // This value represents the database value $array_ids = explode( ',', $ids ); // This will give you an array with all the id's $amount = 10; // Amount of options for ( $i = 0; $i < $amount; $i++ ) { print '<option value=' . $i; if ( in_array( $i, $array_ids ) ) // If the value is in the id's array, then print selected print ' selected'; print '>' . $i . '</option>'; } Something like that? Grtz Erwin

« previous php.general (#122662) next »