05c06-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 41 行

PHP
41
字号
<?php// A function to find the maximum value from a multidimensional array:function recursive_array_max($a) {    // Loop through all entries comparing them to each other    foreach ($a as $value) {        // If this is an array find its maximum.        if (is_array($value)) {            $value = recursive_array_max($value);        }                // Now if this is our first value:        if (!(isset($max))) {            // Store this and move on:            $max = $value;        } else {            // Compare this value to the max, and pick the highest:            $max = $value > $max ? $value : $max;        }    }        // Return the final maximum value:    return $max;}        // Prepare a multidimensional array of numbers:$dimensional = array(    57,    array(3, 35),    array(235, 534, 73, array(3, 4, 956), 6),    14,     2,     array(5, 74, 73)    );// Find the maximum value within this:$max = recursive_array_max($dimensional);// Print out the result: It will be 956echo "<p>The maximum value was: {$max}</p>";?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?