PHP function methods

Source: Internet
Author: User

<?php
No return value, no parameter
/*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= ' height= ' border=1 style= ' background-color:red; ' > $row </table> ";
}
CreateTable ();
No return value, with parameters
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= ' height= ' border=1 style= ' background-color:red; ' > $row </table> ";
}
Createtablebynum (bis);
There are return values, parameters

Function: output the corresponding table according to the parameters passed in
Parameters: Shaping, number of columns, number of rows
Return value: Outputs the table string for the specified row and column

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= ' height= ' border=1 style= ' background-color:red; ' > $row </table> ";
}*/
echo Createtablebynumandreturn (8,8);
/* $a = 100;
$b = 800;
function Outputvar () {
Global $a;//declares a variable that uses the Globals
echo $a;
echo $GLOBALS [' a ']. " ". $GLOBALS [' B ']." <br/> ";
$GLOBALS [' A ']=400;
}
Outputvar ();
echo $a. " <br/> ";
Function Outputvarbyref (& $num) {//value type pass through the value, does not affect the original value, use the & symbol to pass the variable address of the value type, so it affects the original value
$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"); */

Intrinsic functions
/*function parent () {
echo "This is the parent function";
function Sub1 () {
echo "This is the big son";
}
function Sub2 () {
echo "This is the youngest son";
}
}
Parent ();
Sub1 ();
Sub2 ();

PHP function methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.