Analysis of PHP array deletion solutions using functions

Source: Internet
Author: User

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

PHPLIB is the most commonly used base database to provide general transactions. -As mentioned above, the scalability of PHP has entered a period of rapid development. It may be difficult for a non-programmer to extend additional functions for PHP, but it is not difficult for a PHP programmer. -Object-Oriented Programming PHP provides classes and objects. Web-based programming requires Object-Oriented Programming capabilities. PHP supports constructors and extraction classes. -Scalability: traditional web page interactions are achieved through CGI. The CGI program is not ideal for scalability, because it opens an independent process for every running CGI program. Let's take a look at the PHP array deletion code in detail.

PHP array deletion code:

 
 
  1. /**
  2. * Remove blank elements from the array (including elements with only white spaces)
  3. *
  4. * @ Param array $ arr
  5. * @ Param boolean $ trim
  6. */
  7. Copy the Code as follows:
  8. Function array_remove_empty (& $ arr, $Trim=True)
  9. {
  10. Foreach ($ arr as $Key=>$ Value ){
  11. If (is_array ($ value )){
  12. Array_remove_empty ($ arr [$ key]);
  13. } Else {
  14. $Value=Trim($ Value );
  15. If ($Value= ''){
  16. Unset ($ arr [$ key]);
  17. } Elseif ($ trim ){
  18. $ Arr [$ key] = $ value;
  19. }
  20. }
  21. }
  22. }
  23.  
  24. /**
  25. * Convert a two-dimensional array to a hashmap
  26. *
  27. * If the $ valueField parameter is omitted, each item in the conversion result is an array containing all the data of the item.
  28. *
  29. * @ Param array $ arr
  30. * @ Param string $ keyField
  31. * @ Param string $ valueField
  32. *
  33. * @ Return array
  34. */
  35. Copy the Code as follows:
  36. Function array_to_hashmap (& $ arr, $ keyField, $ValueField=Null)
  37. {
  38. $Ret=Array();
  39. If ($ valueField ){
  40. Foreach ($ arr as $ row ){
  41. $ Ret [$ row [$ keyField] = $ row [$ valueField];
  42. }
  43. } Else {
  44. Foreach ($ arr as $ row ){
  45. $ Ret [$ row [$ keyField] = $ row;
  46. }
  47. }
  48. Return $ ret;
  49. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.