① 誰有php程序設計(第2版)(O'RERLY')出版的pdf格式的,請發郵箱:[email protected];
發給你了
看看可不可以
② [PHP開發手冊]在哪裡有買
這東西 沒得賣,手冊在http://www.php.net/manual/zh/index.php,也有離線版的,但是有書買的
③ PHP編程計算兩個時間段是否有交集的實現方法(不算邊界重疊)
本文實例講述了PHP編程計算兩個時間段是否有交集的實現方法。分享給大家供大家參考,具體如下:
優化前的版本:
/**
*
PHP計算兩個時間段是否有交集(邊界重疊不算)
*
*
@param
string
$beginTime1
開始時間1
*
@param
string
$endTime1
結束時間1
*
@param
string
$beginTime2
開始時間2
*
@param
string
$endTime2
結束時間2
*
@return
bool
*/
function
is_time_cross($beginTime1
=
'',
$endTime1
=
'',
$beginTime2
=
'',
$endTime2
=
'')
{
$status
=
$beginTime2
-
$beginTime1;
if
($status
>
0)
{
$status2
=
$beginTime2
-
$endTime1;
if
($status2
>
0)
{
return
false;
}
elseif
($status2
<
0)
{
return
true;
}
else
{
return
false;
}
}
elseif($status
<
0)
{
$status2
=
$endTime2
-
$beginTime1;
if
($status2
>
0)
{
return
true;
}
else
if
($status2
<
0)
{
return
false;
}
else
{
return
false;
}
}
else
{
$status2
=
$endTime2
-
$beginTime1;
if
($status2
==
0)
{
return
false;
}
else
{
return
true;
}
}
}
優化後的版本(條件合並):
/**
*
PHP計算兩個時間段是否有交集(邊界重疊不算)
*
*
@param
string
$beginTime1
開始時間1
*
@param
string
$endTime1
結束時間1
*
@param
string
$beginTime2
開始時間2
*
@param
string
$endTime2
結束時間2
*
@return
bool
*/
function
is_time_cross($beginTime1
=
'',
$endTime1
=
'',
$beginTime2
=
'',
$endTime2
=
'')
{
$status
=
$beginTime2
-
$beginTime1;
if
($status
>
0)
{
$status2
=
$beginTime2
-
$endTime1;
if
($status2
>=
0)
{
return
false;
}
else
{
return
true;
}
}
else
{
$status2
=
$endTime2
-
$beginTime1;
if
($status2
>
0)
{
return
true;
}
else
{
return
false;
}
}
}
測試:
$beginTime1
=
strtotime('2015-08-07
06:30');
$endTime1
=
strtotime('2015-08-07
08:30');
$beginTime2
=
strtotime('2015-08-07
05:30');
$endTime2
=
strtotime('2015-08-07
06:31');
echo
is_time_cross($beginTime1,
$endTime1,
$beginTime2,
$endTime2);//輸出1
PS:這里再為大家推薦幾款時間及日期相關工具供大家參考使用:
在線日期/天數計算器:
http://tools.jb51.net/jisuanqi/date_jisuanqi
在線日期計算器/相差天數計算器:
http://tools.jb51.net/jisuanqi/datecalc
在線日期天數差計算器:
http://tools.jb51.net/jisuanqi/onlinedatejsq
Unix時間戳(timestamp)轉換工具:
http://tools.jb51.net/code/unixtime
更多關於PHP相關內容感興趣的讀者可查看本站專題:《php日期與時間用法總結》、《PHP數組(Array)操作技巧大全》、《PHP基本語法入門教程》、《PHP運算與運算符用法總結》、《php面向對象程序設計入門教程》、《PHP網路編程技巧總結》、《php字元串(string)用法總結》、《php+mysql資料庫操作入門教程》及《php常見資料庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
④ php 簡單的程序設計(輪流攻擊)
胡亂寫了個簡單程序,不過測試程序的時候發現,你的傷害計算有很大的問題。
上面說道:實際傷害=A部隊攻擊力-B部隊防禦力
那麼攻擊最高的騎兵攻擊是30,打在防最低為5的弓兵身上,那麼傷害等於30-5=25,這里倒是沒多大問題,但是又看
實際傷害/B部隊單位血量=本次攻擊殺死敵兵數量,余數進位.
那麼殺死弓兵的數量就等於25/200=0.125 按余數進位也就是1而已 0.125已經是裡面最大的傷害了,所以造成每次無論任意兵種攻擊任意兵種,死亡的單位都是1.
附程序(沒怎麼思考,期待樓下更精簡的演算法):
<?php
//初始化團隊
$team_a=array(
"5"=>set_c("軍團A騎兵甲","cavalry"),
"11"=>set_c("軍團A弓兵甲","archer"),
"14"=>set_c("軍團A弓兵乙","archer"),
"8"=>set_c("軍團A步兵甲","infantry"),
"7"=>set_c("軍團A步兵乙","infantry")
);
$team_b=array(
"8"=>set_c("軍團B騎兵甲","cavalry"),
"9"=>set_c("軍團B騎兵乙","cavalry"),
"13"=>set_c("軍團B弓兵甲","archer"),
"5"=>set_c("軍團B步兵甲","infantry"),
"10"=>set_c("軍團B步兵乙","infantry")
);
//按速度對團隊進行排序
$team_a=spe_sort($team_a);
$team_b=spe_sort($team_b);
//初始化戰斗單位
function set_c($name,$type){
//初始化兵種 infantry 步兵 archer弓兵 cavalry騎兵,兵種=>(攻,防,HP,速度,數量).
$arm=array(
"infantry"=>array("tak"=>20,"def"=>10,"hp"=>250,"spe"=>"20|24","amo"=>120),
"archer"=>array("tak"=>25,"def"=>5,"hp"=>200,"spe"=>"25|27","amo"=>100),
"cavalry"=>array("tak"=>30,"def"=>15,"hp"=>300,"spe"=>"28|30","amo"=>80)
);
$d=$arm[$type];
$d["name"]=$name;
$spe=explode("|",$d["spe"]);
$d["spe"]=rand($spe[0],$spe[1]);
return $d;
}
//速度排序
function spe_sort($array){
foreach($array as $key => $value)
{
$temp[$key] = $value['spe'];
}
arsort($temp);
foreach($temp as $key => $value)
{
$result[$key] = $array[$key];
}
return $result;
}
//戰斗函數 $active=攻擊團隊 $passive=被攻擊團隊
function fight($active,$passive){
//目標選擇規則
$targeting=array(7,4,10,1,13,8,5,11,2,14,9,6,12,3,15);
foreach($active as $k=>$a)
{ foreach($targeting as $t)
{
if(isset($passive[$t]))
{
$hurt=$active[$k]["tak"]-$passive[$t]["def"];
$kill=ceil($hurt/$passive[$t]["hp"]);
$passive[$t]["amo"]=$passive[$t]["amo"]-$kill;
echo "<font color='#0000FF'>".$active[$k]["name"]."</font> 攻擊了 <font color='#0000FF'>". $passive[$t]["name"] ."</font>,共傷害<font color='#ff000'> $hurt </font>點,殺死<font color='#ff000'> $kill </font>個單位.剩餘".$passive[$t]["amo"]."個單位</br>";
if( $passive[$t]["amo"]<=0)
{
echo "×<font color='#ff000'>".$passive[$t]["name"]."</font>被消滅了!</br>";
unset($passive[$t]);
if(!count($passive)){echo "<font color='#ff000'>該軍團已全軍覆沒!戰斗結束....</font>"; die();}
}
break;
}
}
}
echo "-------------------本回合結束,換對方攻擊-------------------</br>";
fight($passive,$active);
}
echo "戰斗開始!</br>";
fight($team_a,$team_b);
?>
⑤ php程序設計
(1)
$newscontent = $_POST['newscontent'];
exit('<script>alert("請輸入新聞內容");history.back();</script>');
$sql = "insert into news (title,content,addtime,clicknum) values ('{$newstitle}','{$newscontent}',NOW(),0)";
$query = $db->exec($sql);
(2)
$sql = "SELECT title,addtime,clicknum FROM news";
$news = $db->getRows($sql);
foreach($news as $one){
echo "標題:{$one['title']}<br>內容:{$one['content']}<br>點擊數:{$one['clicknum']}";
(3)
$newstitle = $_POST['newstitle'];
exit('<script>alert("請輸入標題");history.back();</script>');
⑥ php程序設計選擇題
a.
a.
a.
d. Select * from employees where 姓名 like 『%文%』
d.
d.
b.
cd.
b.
⑦ PHP程序設計的介紹
《PHP程序設計》是北京大學出版社出版的圖書,作者是曾棕根。
⑧ PHP程序設計第2版 第5章 有個錯誤
作者太明顯的錯誤,你的理解是正確的,我在PHP4.3.2上做了測試,結果和你一樣。
測試代碼:
<?php
$arr=array('a'=>1,'b'=>2,'c'=>3);
$sub=array_slice($arr,1,2);
print_r($sub);
?>
運行結果:
D:\temp\>e:\php4.3.2\php.exe a.php
Content-type: text/html
X-Powered-By: PHP/4.3.2
Array
(
[b] => 2
[c] => 3
)
⑨ 怎麼提高php編程能力
要想提高你的PHP編程能力,你可以做兩件事情:1)更扎實的掌握基本編程技能;2)更細微、更深入地了解PHP。
以下總結出的幾條指南導航將有助於提高開發者的PHP編程能力:
一、提高PHP編碼能力的10個細節
或許你並不能從這些細節中學到絕對新的東西(例如「如何對變數和函數做好的命名」,「對代碼做好注釋」,「頻繁測試代碼」),而它們可以讓你鞏固基礎知識。以下幾點解釋了為什麼最好的普通編程實踐在PHP應用軟體開發中尤為重要。
其中10點建議分別為:
1)如何開始良好的開發風格;
2)合適的變數及函數命名;
3)注釋代碼;
4)自己動手做大部分的工作;
5)多方涉獵;
6)了解開發語言的局限性;
7)接受結構上的意見反饋;
8)頻繁的測試代碼;
9)在自己的工程上內嵌程序;
10)不要把每一個文件都分一個文件夾
二、寫出更優PHP代碼的7條法則
以下7種方法列舉出了PHP開發商極有可能面對的問題(例如不使用模板,不合適的封裝,在增刪修改時PHP和SQL的混淆使用等等),對於那些很有可能危害到PHP應用程序運行的各種復雜語句,該指南也提供了多種方法來清除(例如對大容量的網頁減少資料庫查詢)。
以下是關鍵點:
1)在模板中使用可選擇的PHP語法;
2)封裝所有的東西;
3)使用一個資料庫對象;
4)使用增刪查改功能;
5)與調試為友;
6)重視命名;
7)減少資料庫查詢。
⑩ PHP程序設計試卷
1、"php"
2、?>和<?php ; <?php和?>
3、賦值 ; 判斷
4、5
5、這個題太無聊 是在考轉義
6、你簡直太棒了!
7、資料庫地址 ; 資料庫用戶名