<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: php code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 08 Aug 2008 17:56:14 GMT</pubDate>
    <description>DZone Snippets: php code</description>
    <item>
      <title>PHP Select Form Helper</title>
      <link>http://snippets.dzone.com/posts/show/5035</link>
      <description>// takes an array of values and a value to match, and outputs formatted &lt;option&gt;s with the &lt;option&gt; matching $match selected&lt;br /&gt;// must be manually wrapped in &lt;select&gt;&lt;/select to allow for maximum flexibility&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function selectHelper($values, $match)&lt;br /&gt;{&lt;br /&gt;  $keys = array_keys($values);&lt;br /&gt;  $i = 0;&lt;br /&gt;	&lt;br /&gt;  foreach($values as $option)&lt;br /&gt;  {&lt;br /&gt;    $selected = null;&lt;br /&gt;		&lt;br /&gt;    if($match == $keys[$i])&lt;br /&gt;      $selected = " selected";&lt;br /&gt;			&lt;br /&gt;    echo "	&lt;option value=\"".$keys[$i]."\"$selected&gt;".$option."&lt;/option&gt;\n";&lt;br /&gt;		&lt;br /&gt;    $i++;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//sample usage:&lt;br /&gt;$values = array(&lt;br /&gt;  "lb" =&gt; "Pounds",&lt;br /&gt;  "ea" =&gt; "Each",&lt;br /&gt;  "oz" =&gt; "Ounces");&lt;br /&gt;				&lt;br /&gt;  selectHelper($values, $product-&gt;unit);&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 25 Jan 2008 02:13:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5035</guid>
      <author>nathancarnes (Nathan Carnes)</author>
    </item>
  </channel>
</rss>
