PHP Array function Array_walk Usage example, array array_walk_php tutorial

Source: Internet
Author: User
Tags php regular expression

PHP Array function Array_walk Usage example, array array_walk


This article describes the use of PHP array function array_walk. Share to everyone for your reference, as follows:

$words =array ("l" = "lemon", "o" = "Orange", "b" = "banana", "a" and "apple");//define a callback function, output array element function words _print ($value, $key, $prefix) {  echo ' $prefix: $key + $value
\ n ";} Defines a callback function that directly alters the value of the element function Words_alter (& $value, $key) { $value =ucfirst ($value); $key =strtoupper (key);} The value of the output element Array_walk ($words, ' words_print ', ' words ');//Change the value of the element Array_walk ($words, ' words_alter '); echo "
";p Rint_r ($words); echo"
";

Class Internal invocation Example:

Class Arraywalk {  /**  * Properties:  *  /var $body _chunk = Array (' 0 ' = ' dewen ', ' 1 ' = ' PHP ', 2=> ' Linux ');  //VARIABLE METHODS  //////////////////////////////////  function Arraywalk () {  }  function Func_1 () {  print_r ($this->body_chunk);  Array_walk ($this->body_chunk, Array ($this, ' spellstrtolower '));  Print_r ($this->body_chunk);  }  Function Spellstrtolower (& $str) {    $str = Strtolower ($STR);  }} $obj = new Arraywalk (); Echo '
'; $obj->func_1 (); Echo '
';

Add: small make up here to recommend a site of the PHP format beautification of the layout tools to help you in the future of PHP programming code layout:

PHP Code online format Beautification tool:

Http://tools.jb51.net/code/phpformat

In addition, because PHP is a C language style, the following tool can also be used to implement the PHP code format:

C Language Style/html/css/json code formatting beautification tool:
Http://tools.jb51.net/code/ccode_html_css_json

More about PHP related content readers can view this site topic: "PHP array" operation Skills Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Math Skills Summary, "PHP Regular Expression Usage summary", "PHP Operations and Operator Usage Summary", "PHP string Usage Summary" and "PHP common database Operation Skills Summary"

I hope this article is helpful to you in PHP programming.

http://www.bkjia.com/PHPjc/1133078.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133078.html techarticle php Array Function Array_walk Usage example, array Array_walk This example describes the use of PHP array functions array_walk. Share to everyone for your reference, as follows: $words =array ("L" ...

  • 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.