Php array function array_walk usage example, array array_pai_php tutorial

Source: Internet
Author: User
Php array function array_walk usage example, array array_walk. Php array function array_walk usage example. array array_walk this article describes the usage of php array function array_walk. For your reference, see $ wordsarray (l php array function array_walk usage example, array array_walk

This article describes how to use the php array function array_walk. We will share this with you for your reference. The details are as follows:

$ Words = array ("l" => "lemon", "o" => "orange", "B" => "banana ", "a" => "apple"); // defines a callback function and outputs the function words_print ($ value, $ key, $ prefix) {echo "$ prefix: $ key => $ value
\ N ";}// define a callback function to directly change the value of the element function words_alter (& $ value, $ key) {$ value = ucfirst ($ value ); $ key = strtoupper (key);} // array_walk ($ words, 'Words _ print ', 'Word') of the output element '); // change the value of the element array_walk ($ words, 'Words _ alter '); echo"
";print_r($words);echo "
";

Class internal call 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 '
';

Supplement: The editor recommends a php formatting and formatting typographical tool on this site to help you typeset code in future PHP programming:

Php code online formatting and beautification tools:

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

In addition, because php belongs to the C language style, the following tool can also format php code:

C language style/HTML/CSS/json code formatting and beautification tools:
Http://tools.jb51.net/code/ccode_html_css_json

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.