PHP函數方法

來源:互聯網
上載者:User

標籤:oba   order   output   for   全域   numa   ++   index   ble   

<?php
//無傳回值,無參數
/*function CreateTable(){
$col="";
//echo $col;
$cindex=0;
while($cindex<10){
$col.="<td></td>";
$cindex++;
}
$rindex=0;
$row="";
while($rindex<10){
$row.="<tr> $col </tr>";
$rindex++;
}
echo "<table width=‘200‘ height=‘200‘ border=1 style=‘background-color:red;‘>$row</table>";
}
//CreateTable();
//無傳回值,有參數
function CreateTableByNum($colNum,$rowNum){
$col="";
//echo $col;
$cindex=0;
while($cindex<$colNum){
$col.="<td></td>";
$cindex++;
}
$rindex=0;
$row="";
while($rindex<$rowNum){
$row.="<tr> $col </tr>";
$rindex++;
}
echo "<table width=‘200‘ height=‘200‘ border=1 style=‘background-color:red;‘>$row</table>";
}
CreateTableByNum(4,4);
//有傳回值,有參數

功能:根據傳入的參數輸出對應的表格
參數:整形,列的數量,行的數量
傳回值:輸出指定行和列的表格字串

function CreateTableByNumAndReturn($colNum,$rowNum){
$col="";
//echo $col;
$cindex=0;
while($cindex<$colNum){
$col.="<td></td>";
$cindex++;
}
$rindex=0;
$row="";
while($rindex<$rowNum){
$row.="<tr> $col </tr>";
$rindex++;
}
return "<table width=‘200‘ height=‘200‘ border=1 style=‘background-color:red;‘>$row</table>";
}*/
//echo CreateTableByNumAndReturn(8,8);
/* $a=100;
$b=800;
function outputVar(){
//global $a;//表示聲明使用全域的變數
//echo $a;
echo $GLOBALS[‘a‘]." ".$GLOBALS[‘b‘]."<br/>";
$GLOBALS[‘a‘]=400;
}
outputVar();
echo $a."<br/>";
function outputVarByref(&$num){//實值型別傳遞過程中是將值進行傳遞,不會影響原來的值,使用&符號表示將實值型別的變數地址傳遞,所以會影響原來的值
$num=500;
}
outputVarByref($a);
echo $a;
function counts(){
static $index=0;
echo $index."<br/>";
$index++;
}
for($i=0;$i<3;$i++){
cOuntS();
}
counTs();
echo function_exists("opendir");*/

//內建函式
/*function parent(){
echo "這是父函數";
function sub1(){
echo "這是大兒子";
}
function sub2(){
echo "這是小兒子";
}
}
parent();
sub1();
sub2();

PHP函數方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.