【发布时间】:2015-09-21 20:37:44
【问题描述】:
我正在尝试创建一个接受数字数组的函数,然后, 从给定数组中返回最小和最大数 作为使用数组和 for 循环的关联数组。
例如:
$sample = array( 135, 2.4, 2.67, 1.23, 332, 2, 1.02);
$output = get_max_and_min($sample);
var_dump($output);
//$output should be equal to array('max' => 332, 'min' => 1.02);*/
到目前为止,这是我的代码:
$sample = array( 135, 2.4, 2.67, 1.23, 332, 2, 1.02);
function get_max_and_min($array){
for($i=0; $i>=$array; $i++){
echo $i;
}
}
$output = get_max_and_min($sample);
echo $output;
/* var_dump($output); */
有什么想法吗?谢谢!
【问题讨论】:
-
你能告诉我它是如何工作的吗?
-
演示如下。
-
我正在寻找一些方法来使用 PLAIN FOR LOOPS 来做到这一点。这个我需要一点逻辑。