<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>代码收藏 &#187; 数组</title> <atom:link href="http://code.9enjoy.com/tag/%e6%95%b0%e7%bb%84/feed/" rel="self" type="application/rss+xml" /><link>http://code.9enjoy.com</link> <description>收集网站开发时常用到的代码(asp,php,js等)，以函数为主</description> <lastBuildDate>Mon, 24 Jan 2011 14:23:49 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.1</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>二维数组的array_unique函数</title><link>http://code.9enjoy.com/php/array_unique_fb/</link> <comments>http://code.9enjoy.com/php/array_unique_fb/#comments</comments> <pubDate>Thu, 04 Mar 2010 02:49:55 +0000</pubDate> <dc:creator>enjoy</dc:creator> <category><![CDATA[php]]></category> <category><![CDATA[数组]]></category> <category><![CDATA[重复]]></category><guid
isPermaLink="false">http://code.9enjoy.com/?p=167</guid> <description><![CDATA[关于php的array_unique函数，此函数只适用于一维数组，对多维数组并不适用，以下提供一个二维数组的array_unique函数 
//二维数组去掉重复值
function array_unique_fb($array2D){  
     foreach ($array2D as $v){
         $v = join(&#8220;,&#8221;,$v);              //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
         $temp[] = $v;
     }
     $temp = array_unique($temp);      //去掉重复的字符串,也就是重复的一维数组
    foreach ($temp as $k =&#62; $v){
        $temp[$k] = explode(&#8220;,&#8221;,$v);       //再将拆开的数组重新组装
    }
    return $temp;
}
原文：http://blog.sina.com.cn/s/blog_60c5cbf50100e4qz.html
]]></description> <content:encoded><![CDATA[<p>关于php的array_unique函数，此函数只适用于一维数组，对多维数组并不适用，以下提供一个二维数组的array_unique函数 </p><p>//二维数组去掉重复值<br
/> function array_unique_fb($array2D){  <br
/>      foreach ($array2D as $v){<br
/>          $v = join(&#8220;,&#8221;,$v);              //降维,也可以用implode,将一维数组转换为用逗号连接的字符串<br
/>          $temp[] = $v;<br
/>      }</p><p>     $temp = array_unique($temp);      //去掉重复的字符串,也就是重复的一维数组<br
/>     foreach ($temp as $k =&gt; $v){<br
/>         $temp[$k] = explode(&#8220;,&#8221;,$v);       //再将拆开的数组重新组装<br
/>     }<br
/>     return $temp;<br
/> }</p><p>原文：<a
href="http://blog.sina.com.cn/s/blog_60c5cbf50100e4qz.html">http://blog.sina.com.cn/s/blog_60c5cbf50100e4qz.html</a></p> <img
src="http://code.9enjoy.com/?ak_action=api_record_view&id=167&type=feed" alt="" />]]></content:encoded> <wfw:commentRss>http://code.9enjoy.com/php/array_unique_fb/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>php数组二分法查找</title><link>http://code.9enjoy.com/php/array-search/</link> <comments>http://code.9enjoy.com/php/array-search/#comments</comments> <pubDate>Tue, 12 Jan 2010 14:43:48 +0000</pubDate> <dc:creator>enjoy</dc:creator> <category><![CDATA[php]]></category> <category><![CDATA[二分法]]></category> <category><![CDATA[数组]]></category><guid
isPermaLink="false">http://code.9enjoy.com/?p=138</guid> <description><![CDATA[&#60;?php
//search函数 其中$array为数组，$k为要找的值，$low为查找范围的最小键值，$high为查找范围的最大键值
function search($array, $k, $low=0, $high=0)
{
if(count($array)!=0 and $high == 0)                 //判断是否为第一次调用
{
$high = count($array);
}
if($low &#60;= $high)                                //如果还存在剩余的数组元素
{
$mid = intval(($low+$high)/2);                  //取$low和$high的中间值
if ($array[$mid] == $k)     [...]]]></description> <content:encoded><![CDATA[<div
id="_mcePaste">&lt;?php</div><div
id="_mcePaste">//search函数 其中$array为数组，$k为要找的值，$low为查找范围的最小键值，$high为查找范围的最大键值</div><div
id="_mcePaste">function search($array, $k, $low=0, $high=0)</div><div
id="_mcePaste">{</div><div
id="_mcePaste">if(count($array)!=0 and $high == 0)                 //判断是否为第一次调用</div><div
id="_mcePaste">{</div><div
id="_mcePaste">$high = count($array);</div><div
id="_mcePaste">}</div><div
id="_mcePaste">if($low &lt;= $high)                                //如果还存在剩余的数组元素</div><div
id="_mcePaste">{</div><div
id="_mcePaste">$mid = intval(($low+$high)/2);                  //取$low和$high的中间值</div><div
id="_mcePaste">if ($array[$mid] == $k)                         //如果找到则返回</div><div
id="_mcePaste">{</div><div
id="_mcePaste">return $mid;</div><div
id="_mcePaste">}</div><div
id="_mcePaste">elseif ($k &lt; $array[$mid])                       //如果没有找到，则继续查找</div><div
id="_mcePaste">{</div><div
id="_mcePaste">return search($array, $k, $low, $mid-1);</div><div
id="_mcePaste">}</div><div
id="_mcePaste">else</div><div
id="_mcePaste">{</div><div
id="_mcePaste">return search($array, $k, $mid+1, $high);</div><div
id="_mcePaste">}</div><div
id="_mcePaste">}</div><div
id="_mcePaste">return -1;</div><div
id="_mcePaste">}</div><div
id="_mcePaste">$array = array(4,5,7,8,9,10);                           //测试search函数</div><div
id="_mcePaste">echo search($array, 8);                             //调用search函数并输出查找结果</div><div
id="_mcePaste">?&gt;</div><div
id="_mcePaste"></div><p>原文：http://blog.csdn.net/zhuzhao/archive/2009/03/09/3969044.aspx</p> <img
src="http://code.9enjoy.com/?ak_action=api_record_view&id=138&type=feed" alt="" />]]></content:encoded> <wfw:commentRss>http://code.9enjoy.com/php/array-search/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>in_array &#8211; js模拟php中的in_array</title><link>http://code.9enjoy.com/javascript/in_array/</link> <comments>http://code.9enjoy.com/javascript/in_array/#comments</comments> <pubDate>Fri, 25 Apr 2008 15:04:23 +0000</pubDate> <dc:creator>enjoy</dc:creator> <category><![CDATA[javascript]]></category> <category><![CDATA[array]]></category> <category><![CDATA[数组]]></category> <category><![CDATA[模拟]]></category><guid
isPermaLink="false">http://code.itlearner.com/?p=34</guid> <description><![CDATA[in_array<br/><br/>in_array -- 检查数组中是否存在某个值<br/>说明<br/>bool in_array ( mixed needle, array haystack [, bool strict] )<br/><br/><br/>在 haystack 中搜索 needle，如果找到则返回 TRUE，否则返回 FALSE。 <br/><br/><br/>[CODE_LITE]function in_array(needle, haystack) {<br/> if(typeof needle == 'string' &#124;&#124; typeof needle == 'number') {<br/>...
]]></description> <content:encoded><![CDATA[<p>in_array</p><p>in_array &#8212; 检查数组中是否存在某个值<br
/> 说明<br
/> bool in_array ( mixed needle, array haystack [, bool strict] )</p><p>在 haystack 中搜索 needle，如果找到则返回 TRUE，否则返回 FALSE。</p><p
class="code"><code>function in_array(needle, haystack) {<br
/> if(typeof needle == 'string' || typeof needle == 'number') {<br
/> for(var i in haystack) {<br
/> if(haystack[i] == needle) {<br
/> return true;<br
/> }<br
/> }<br
/> }<br
/> return false;<br
/> }</code></p> <img
src="http://code.9enjoy.com/?ak_action=api_record_view&id=34&type=feed" alt="" />]]></content:encoded> <wfw:commentRss>http://code.9enjoy.com/javascript/in_array/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk
Database Caching 8/14 queries in 0.005 seconds using disk

Served from: code.itlearner.com @ 2012-02-07 02:52:04 -->
