<?php
//求数组的平均值
$a3 = array(
array(11,12, 13),
array(21,22,23, 24, 25),
array(31,32,33, 35),
array(41,42,43)
);
$length = count($a3);
$count = 0;
$sum = 0;
for($i=0; $i<$length; ++$i){
$length2 = count($a3[$i]);
for($j=0; $j<$length2; ++$j){
$sum += $a3[$i][$j];
++$count;
}
}
$average = $sum / $count;
echo "数组的平均值是:$average";
echo "<hr>"; //一个“不整齐”数字数组,如下所示,求其平均值:
$a4 = array(
1,
array(21,22,23, 24, 25),
3,
array( 41, 42, 43,array(50, 51, 52) )
);
$sum = 0;
$count = 0;
function digui($arr){
$length = count($arr);
for($i=0; $i<$length; ++$i){
$length2 = count($arr[$i]);
if($length2==1){
$GLOBALS['sum'] += $arr[$i];
++$GLOBALS['count'];
}
else{
digui($arr[$i]);
}
}
return $GLOBALS['sum']/$GLOBALS['count'];
}
$a = digui($a4);
echo $a;
echo '<hr>'; //求一个整数数组中的最小的奇数,如果没有奇数,则直接输出“没有奇数”,否则输出该数。
$arr = array(56,76,4,98,6,3,5);
$length = count($arr);
for($i=0; $i<$length; ++$i){
if($arr[$i]%2!=0){
$arr2[]=$arr[$i];
}
}
if(!empty($arr2)){
$min = $arr2[0];
for($j=0; $j<count($arr2); ++$j){
if($min>$arr2[$j]){
$min = $arr2[$j];
}
}
echo "最小的奇数为:$min";
}
else{
echo "大哥,没有奇数!";
} ?>

2nd day的更多相关文章

  1. Entity Framework 6 Recipes 2nd Edition 译 -> 目录 -持续更新

    因为看了<Entity Framework 6 Recipes 2nd Edition>这本书前面8章的翻译,感谢china_fucan. 从第九章开始,我是边看边译的,没有通读,加之英语 ...

  2. 参加 Tokyo Westerns / MMA CTF 2nd 2016 经验与感悟 TWCTF 2016 WriteUp

    洒家近期参加了 Tokyo Westerns / MMA CTF 2nd 2016(TWCTF) 比赛,不得不说国际赛的玩法比国内赛更有玩头,有的题给洒家一种一看就知道怎么做,但是做出来还需要洒家拍一 ...

  3. Recruit Coupon Purchase Winner's Interview: 2nd place, Halla Yang

    Recruit Coupon Purchase Winner's Interview: 2nd place, Halla Yang Recruit Ponpare is Japan's leading ...

  4. 架构师书单 2nd Edition--转载

    作者:江南白衣,原文出处: http://blog.csdn.net/calvinxiu/archive/2007/03/06/1522032.aspx,转载请保留. 为了2007年的目标,列了下面待 ...

  5. Otto Product Classification Winner's Interview: 2nd place, Alexander Guschin ¯\_(ツ)_/¯

    Otto Product Classification Winner's Interview: 2nd place, Alexander Guschin ¯\_(ツ)_/¯ The Otto Grou ...

  6. The 2nd tip of DB Query Analyzer

    The 2nd tip of DB Query Analyzer                               Ma Genfeng   (Guangdong Unitoll Servi ...

  7. Reading task(Introduction to Algorithms. 2nd)

    Introduction to Algorithms 2nd ed. Cambridge, MA: MIT Press, 2001. ISBN: 9780262032933. Introduction ...

  8. 第十五周翻译-《Pro SQL Server Internals, 2nd edition》

    <Pro SQL Server Internals, 2nd edition> 作者:Dmitri Korotkevitch 翻译:赖慧芳 译文: 55-58页 第三章 统计 SQL Se ...

  9. 第十四周翻译-《Pro SQL Server Internals, 2nd edition》

    <Pro SQL Server Internals, 2nd edition> 作者:Dmitri Korotkevitch 翻译:赖慧芳 译文: 设计和优化索引 定义一种应用于所有地方的 ...

  10. 第十三周翻译-《Pro SQL Server Internals, 2nd edition》

    <Pro SQL Server Internals, 2nd edition> 作者:Dmitri Korotkevitch 翻译:赖慧芳 译文: 聚集索引 聚集索引指示表中数据的物理顺序 ...

随机推荐

  1. 115个Java面试题和答案——终极列表

    from http://www.importnew.com/10980.html#collection http://www.importnew.com/11028.html 下面的章节分为上下两篇, ...

  2. linux负载均衡

    1.linux lvs nat实现负载均衡 添加两块网卡并开启路由管道 > /proc/sys/net/ipv4/ip_forward //开始路由管道 安装ipvsadm yum instal ...

  3. 关于css中透明度继承的问题

    今天工作中发现了一个问题,透明度的继承问题,如下图所示: 容器div2就“继承了”外面容器div1的透明度,也变成了70%的透明.容器里面的字体颜色和图片都“继承”了div1,具体代码如下: 可是设计 ...

  4. IE 6最小最大宽度与高度的写法

    最小最大宽度,最小最大高度,这是CSS很常见的一个要求.在现代浏览器中,一个 min-height,min-width 就可以解决问题,但是在IE系列,比如IE6则比较繁琐一点.下面总结一些IE 6下 ...

  5. STM32学习笔记——SPI串行通讯(向原子哥学习)

    一.SPI  简介 SPI是 Serial Peripheral interface 的缩写,就是串行外围设备接口.SPI 接口主要应用在  EEPROM, FLASH,实时时钟,AD 转换器,还有数 ...

  6. Kendo UI for Angular 2 控件

    Kendo UI for Angular 2 控件 伴随着 Angular 2 的正式 release,Kendo UI for Angular 2 的第一批控件已经发布了,当前是 Beta 版本,免 ...

  7. [转] Java 8的新特性

    简介 毫无疑问,Java 8是Java自Java 5(发布于2004年)之后的最重要的版本.这个版本包含语言.编译器.库.工具和JVM等方面的十多个新特性.在本文中我们将学习这些新特性,并用实际的例子 ...

  8. iOS常用的加密方式--备用

    MD5 iOS代码加密 创建MD5类,代码如下 #import <Foundation/Foundation.h> @interface CJMD5 : NSObject +(NSStri ...

  9. SSH2中实例化不了Action的一个原因

    <!-- 流程管理 --> <action name="flow_*" class="workFlowAction" method=" ...

  10. win平台下, 检测网络是否连接最好的办法

    [Delphi]检查URL是否有效的函数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 function CheckUr ...