Php doubles the number of cells in a multi-dimensional array. _ PHP Tutorial

Source: Internet
Author: User
Php doubles the number of cells in a multi-dimensional array. Php doubles the number of cells in a multi-dimensional array. This article describes how php doubles the number of cells in a multi-dimensional array. I would like to share with you how php doubles the unit value (number) in a multi-dimensional array, doubling the number of dimensions.

This example describes how to double the unit value (number) in a multi-dimensional array in php. Share it with you for your reference. The specific analysis is as follows:

Premise: a multi-dimensional array with each minimum unit value being a number.
Requirement: write a function to double the minimum unit value.

The code is as follows:

<? Php $ arr = array (1, 3, 'a' => 20, 'B' => array (2, 4, 6, 'C' => 7 )); function arr2 ($ arr) {foreach ($ arr as $ key => $ v) {if (! Is_array ($ v) {$ arr [$ key] * = 2;} else {$ arr [$ key] = arr2 ($ arr [$ key]);} return $ arr;} echo"
";print_r(arr2($arr));?>

Use the functions provided by the system to solve the problem as follows:

<? Php $ arr = array (1, 3, 'a' => 20, 'B' => array (2, 4, 6, 'C' => 7 )); function t (& $ arr) {$ arr * = 2;} echo"
";array_walk_recursive($arr,'t');print_r($arr);?>

I hope this article will help you with php programming.

This article describes how php doubles the number of cells in a multi-dimensional array. Share it with you...

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.