note 68682 added to function.array

From: Date: Mon, 07 Aug 2006 04:48:30 +0000
Subject: note 68682 added to function.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-115602@lists.php.net to get a copy of this message
When using an array to create a list of keys and values for a select box generator which will consist of states I found using "NULL" as an index and ""(empty value) as a value to be useful: <?php $states = array( 0 => 'Select a State', NULL => '', 1 => 'AL - Alabama', 2 => 'AK - Alaska', # And so on ... ); $select = '<select name="state" id="state" size="1">'."\r\n"; foreach($states as $key => $value){ $select .= "\t".'<option value="'.$key.'">' . $value.'</option>'."\r\n"; } $select .= '</select>'; echo $select; ?> This will print out: <select name="state" id="state" size="1"> <option value="0">Select a State</option> <option value=""></option> <option value="1">AL - Alabama</option> <option value="2">AK - Alaska</option> # And so on ... </select> Now a user has a blank value to select if they later decide to not provide their address in the form. The first two options will return TRUE when checked against the php function - EMPTY() after the form is submitted when processing the form ---- Server IP: 216.194.113.175 Probable Submitter: 65.189.38.162 ---- X-Spam-Status: No, hits=4.0 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_20_30,HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.array.php Edit -- https://master.php.net/note/edit/68682 Del: integrated -- https://master.php.net/note/delete/68682/integrated Del: useless -- https://master.php.net/note/delete/68682/useless Del: bad code -- https://master.php.net/note/delete/68682/bad+code Del: spam -- https://master.php.net/note/delete/68682/spam Del: non-english -- https://master.php.net/note/delete/68682/non-english Del: in docs -- https://master.php.net/note/delete/68682/in+docs Del: other reasons-- https://master.php.net/note/delete/68682 Reject -- https://master.php.net/note/reject/68682 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115602) next »