Php method for doubling the value (number) of each cell in a multidimensional array
This article mainly introduces the PHP implementation of multi-dimensional array of each cell value (number) Doubling method, involving PHP operation array of skills, the need for friends can refer to the next
The example in this paper is about how to double the value (number) of each cell in a multidimensional array in PHP. Share to everyone for your reference. The specific analysis is as follows:
Premise: A multidimensional array, each of its smallest cell values is a number.
Requirement: Write a function that doubles the minimum unit value.
The code is as follows
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$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 following methods:
?
1 2 3 4 5 6 7 8 9 |
$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 is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/966907.html www.bkjia.com true http://www.bkjia.com/PHPjc/966907.html techarticle a method of doubling the value (number) of each cell in a multidimensional array in PHP This article mainly introduces the method of PHP to realize the doubling of each cell value (number) in multidimensional array, which involves the technique of PHP operation Array ...