Re: Creating Arrays
| From: | Matt McClanahan | Date: | Wed, 11 Apr 2001 22:33:39 +0000 |
| Subject: | Re: Creating Arrays | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-48213@lists.php.net to get a copy of this message | ||
On Wed, Apr 11, 2001 at 03:55:38PM -0600, Ashley M. Kirchner wrote:
> "Rodney J. Woodruff" wrote:
>
> > http://www.php.net/manual/en/function.msql-fetch-array.php
(snip)
> I need that result into the following:
> $items = array(0 => "Undefined", 1 => "Work", 2 =>
> "Personal");
Here's a hint.
$arr[$key] = $value;
Define $key and $value from the row data that mysql_fetch_array
gives you.
> Reason is, I pass that $items variable to the following function:
>
> function MakeSelect($items, $selected) {
> $str = "";
> while(list($value, $name) = each($items)) {
> $str .= "<option value=\"$value\"" . ($value != $selected ? \
> ">" : " selected>") . "$name\n";
> }
> return $str;
> }
For the record, you're thinking about list() backwards. In your
function, the array keys will go into $value, and the values will go
into $name.
HTH,
Matt