簡體   English   中英

全局變量和函數

[英]Global Variables and Functions

如果我有一個需要使用$ foo的函數,

global $foo如此皺眉,

我如何才能讓我的函數在不全局的情況下訪問變量? 還有我不知道的另一種方法或方法嗎?

嘗試這樣的事情。

<?php
    $name = "batman";

    function get_details($name,$age){
        $temp_str = "Name: ".$name."<br />Age: ".$age;
        return($temp_str);
    }

    echo get_details($name,35); // passing through name as a variable and the age as just text...
?>

給...

Name: batman
Age: 35

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM