<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Goldfish's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 08 Aug 2008 21:07:35 GMT</pubDate>
    <description>DZone Snippets: Goldfish's Code Snippets</description>
    <item>
      <title>indexOf an array element</title>
      <link>http://snippets.dzone.com/posts/show/2342</link>
      <description>Finds the first instance of an element ($needle) in an array ($haystack).  It works in ascending order (from element 0 to the array's length), can be easily modified to work in reverse if required.  Will return either the index of the first occurance of false if hasn't been found.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function indexOf($needle, $haystack) {                // conversion of JavaScripts most awesome&lt;br /&gt;        for ($i=0;$i&lt;count($haystack);$i++) {         // indexOf function.  Searches an array for&lt;br /&gt;                if ($haystack[$i] == $needle) {       // a value and returns the index of the *first*&lt;br /&gt;                        return $i;                    // occurance&lt;br /&gt;                }&lt;br /&gt;        }&lt;br /&gt;        return false;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 30 Jul 2006 19:15:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2342</guid>
      <author>goldfish ()</author>
    </item>
    <item>
      <title>Integer to alphanumeric character</title>
      <link>http://snippets.dzone.com/posts/show/2341</link>
      <description>A function that converts an integer between 0 and 61 into an alphanumberic character.  Ranges from 0-9, A-Z, a-z.  Very handy for generating random strings and stuff like that.  &lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;function map_char($num) { &lt;br /&gt;   $int = $num; $int+=48;&lt;br /&gt;   ($int &gt; 57) ? $int += 7 : null;&lt;br /&gt;   ($int &gt; 90) ? $int += 6 : null;&lt;br /&gt;   return chr($int);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 30 Jul 2006 19:12:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2341</guid>
      <author>goldfish ()</author>
    </item>
    <item>
      <title>Reverse switch</title>
      <link>http://snippets.dzone.com/posts/show/2318</link>
      <description>Handy technique if you want to use more complex comparisons other than == in a switch statement.  Much tidier than the elseif equivilant.  &lt;br /&gt;&lt;code&gt;&lt;br /&gt;switch(true) {&lt;br /&gt;&lt;br /&gt;   case $x == "hello":&lt;br /&gt;      // $x is hello&lt;br /&gt;&lt;br /&gt;   case is_numeric($x):&lt;br /&gt;      // $x is a number&lt;br /&gt;&lt;br /&gt;   case $x &lt; 10:&lt;br /&gt;      // $x is less than 10&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 20 Jul 2006 20:22:41 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2318</guid>
      <author>goldfish ()</author>
    </item>
  </channel>
</rss>
