Home > Backend Development > PHP Tutorial > Analysis of PHP array deletion solution using functions_PHP tutorial

Analysis of PHP array deletion solution using functions_PHP tutorial

WBOY
Release: 2016-07-15 13:27:23
Original
753 people have browsed it

PHP is one of the more commonly used programming technologies, so I studied PHP array deletion and shared it with you here. I hope it will be useful to everyone. PHP is a server-side scripting language that is easy to learn and use. With very little programming knowledge you can use PHP to build a truly interactive WEB site.

PHPLIB is the most commonly used series of base libraries that can provide general transaction needs. - Scalability As mentioned earlier, PHP has entered a period of rapid development. It may be difficult for a non-programmer to extend additional functionality to PHP, but it is not difficult for a PHP programmer. - Object-oriented programming PHP provides classes and objects. Web-based programming work requires object-oriented programming skills. PHP supports constructors, extracted classes, etc. - Scalability Traditionally, the interaction of web pages is achieved through CGI. The scalability of CGI programs is not very ideal because it opens an independent process for each running CGI program. Let's take a detailed look at the PHP array deletion code.

PHP array deletion code:

<ol class="dp-xml">
<li class="alt"><span><span>/**   </span></span></li>
<li class=""><span>* 从数组中删除空白的元素(包括只有空白字符的元素)   </span></li>
<li class="alt"><span>*   </span></li>
<li class=""><span>* @param array $arr   </span></li>
<li class="alt"><span>* @param boolean $trim   </span></li>
<li class=""><span>*/   </span></li>
<li class="alt"><span>复制代码 代码如下:  </span></li>
<li class="">
<span>function array_remove_empty(& $arr, $</span><span class="attribute">trim</span><span> = </span><span class="attribute-value">true</span><span>)   </span>
</li>
<li class="alt"><span>{   </span></li>
<li class="">
<span>foreach ($arr as $</span><span class="attribute">key</span><span> =</span><span class="tag">></span><span> $value) {   </span>
</li>
<li class="alt"><span>if (is_array($value)) {   </span></li>
<li class=""><span>array_remove_empty($arr[$key]);   </span></li>
<li class="alt"><span>} else {   </span></li>
<li class="">
<span>$</span><span class="attribute">value</span><span> = </span><span class="attribute-value">trim</span><span>($value);   </span>
</li>
<li class="alt">
<span>if ($</span><span class="attribute">value</span><span> == '') {   </span>
</li>
<li class=""><span>unset($arr[$key]);   </span></li>
<li class="alt"><span>} elseif ($trim) {   </span></li>
<li class=""><span>$arr[$key] = $value;   </span></li>
<li class="alt"><span>}   </span></li>
<li class=""><span>}   </span></li>
<li class="alt"><span>}   </span></li>
<li class=""><span>}   </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>/**   </span></li>
<li class="alt"><span>* 将一个二维数组转换为 hashmap   </span></li>
<li class=""><span>*   </span></li>
<li class="alt"><span>* 如果省略 $valueField 参数,则转换结果每一项为包含该项所有数据的数组。   </span></li>
<li class=""><span>*   </span></li>
<li class="alt"><span>* @param array $arr   </span></li>
<li class=""><span>* @param string $keyField   </span></li>
<li class="alt"><span>* @param string $valueField   </span></li>
<li class=""><span>*   </span></li>
<li class="alt"><span>* @return array   </span></li>
<li class=""><span>*/   </span></li>
<li class="alt"><span>复制代码 代码如下:  </span></li>
<li class="">
<span>function array_to_hashmap(& $arr, $keyField, $</span><span class="attribute">valueField</span><span> = </span><span class="attribute-value">null</span><span>)   </span>
</li>
<li class="alt"><span>{   </span></li>
<li class="">
<span>$</span><span class="attribute">ret</span><span> = </span><span class="attribute-value">array</span><span>();   </span>
</li>
<li class="alt"><span>if($valueField) {   </span></li>
<li class=""><span>foreach ($arr as $row) {   </span></li>
<li class="alt"><span>$ret[$row[$keyField]] = $row[$valueField];   </span></li>
<li class=""><span>}   </span></li>
<li class="alt"><span>} else {   </span></li>
<li class=""><span>foreach($arr as $row) {   </span></li>
<li class="alt"><span>$ret[$row[$keyField]] = $row;   </span></li>
<li class=""><span>}   </span></li>
<li class="alt"><span>}   </span></li>
<li class=""><span>return $ret;   </span></li>
<li class="alt"><span>}  </span></li>
</ol>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446535.htmlTechArticlePHP is one of the more commonly used programming technologies, so I studied PHP array deletion and took it out here and Share it with everyone, I hope it will be useful to everyone. PHP is easy to learn and use...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template