PHP学习笔记——函数

<?php
 //PHP 之自定义函数
 /**
  * 不带参数的函数
  */
    function functionTest(){
     echo "this is a function";
    }
    functionTest();
    echo "<br>";
    /**
     * 带参数的函数
     */
   function funcationArea($r){
      echo "面积为:".$r*$r*pi();
   } 
   funcationArea(10);
   /**
    * 带返回值得函数
    */
   echo "<br>";
   function  funcationArea2($k){
      $c=$k*$k*pi();
      return $c;
   } 
   $area=funcationArea2(50);
   echo "带返回值得函数:".$area;
   /**
    * 返回多个值得函数,即返回数组
    */
   echo "<br>";
   function functionArray($name,$age){
     $arr=array($name,$age);
     return $arr;
   }
   $arr=functionArray("zuo","26");
   echo "array:".$arr[0];
   echo "<br>";
   /**
    * 带有默认值得函数
    */
   function funcationArea3($r=100){
    echo "默认面积为:".$r*$r*pi();
   }
   funcationArea3();
   echo "<br>";
   /**
    * 函数中的引用传参
    */
   $c=10;
   function functionChang(&$c){
     $c=$c*$c;
   }
   functionChang($c);
   echo 'this is c: '.$c;
   /**
    * 全局变量的使用
    */
   $x=12;
   echo "<br>";
   function changX(){
     global $x;
     $x=14;
   }
   changX();
   echo 'this is x: '.$x;
   /**
    * 超级全局变量使用
    */
   echo "<br>";
   $GLOBALS['g']=7;
   function  superGlobal(){
    $GLOBALS['g']=100;
   }
   superGlobal();
   echo "this is super global: ".$GLOBALS['g'];
?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值