PHP Array function array_walk usage and examples

Source: Internet
Author: User
This article mainly introduces the PHP array function Array_walk usage, analyzes the use of the user function of each member in the Array_walk log set, the need for friends can refer to the following

Specific 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 <br>\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 "<pre>"; Print_r ($words); echo "</pre>";

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 ' <PRE> '; $obj->func_1 (); Echo ' </PRE> ';

Summary: The above is the entire content of this article, I hope to be able to help you learn.

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.