In our daily development work, the operation of arrays is indispensable. Arrays can be said to be the most important method in PHP data applications. Arrays are a very powerful data type and have rich functions. Operation functions are also used very frequently, so today we will introduce to you the development of PHP array operations!
First we need to download the PHP array operation class library required for this course: http://www.php.cn/xiazai/leiku/793
Then after the download is complete, find the php file library we need, extract it to a local directory, and then continue to create a new php file!
Then we will call this class in the new php file and instantiate this class:
<?php include_once "codeshuzu.php"; $obj = new ArrayHelper; //实例化此类 //从数组中删除空白的元素(包括只有空白字符的元素) $arr = array("","php.cn"," "); $obj->removeEmpty($arr); echo "从数组中删除空白的元素(包括只有空白字符的元素):"; var_dump($arr); echo "<hr>"; //从一个二维数组中返回指定键的所有值 $arr = array( array('name' => "php中文网", 'value' => 'www.php.cn'), array('name' => 2, 'value' => '2-1'),); $key = $obj->getCols($arr,"value"); echo "从一个二维数组中返回指定键的所有值:"; var_dump($key); echo "<hr>"; //将一个二维数组转换为 HashMap,并返回结果 $arr = array( array('name' => "php中文网", 'value' => 'www.php.cn'), array('name' => 2, 'value' => '2-1'),); $key = $obj->toHashmap($arr,"name","value"); echo "将一个二维数组转换为 HashMap,并返回结果:"; var_dump($key); ?>
The result of running the file is as shown below;
Explanation:
In the above example, I just randomly called several functions in the class Example, more friends can try it themselves!
The above is the detailed content of PHP array operation development examples and sharing of ideas. For more information, please follow other related articles on the PHP Chinese website!