久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

PHP 中的變量 - 它們的目的是什么?

Variable variables in PHP - What is their purpose?(PHP 中的變量 - 它們的目的是什么?)
本文介紹了PHP 中的變量 - 它們的目的是什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在 PHP 中有一個正式稱為變量變量"的功能,其中可以分配變量變量.變量變量將一個變量的值作為新變量的名稱!例如:

In PHP there's a functionality officially called "Variable Variables" where one can assign variable variables. A variable variable takes the value of one variable as the name for a new variable! For example:

$name='Joe';
$$name='Smith'; // could also be written as ${$name}='Smith'

第一個變量 $name 包含值 'Joe',而第二個變量名為 $Joe,值為 'Smith'.考慮到 PHP 變量區分大小寫!

The first variable $name contains the value 'Joe', while the second is variable named $Joe with the value 'Smith'. Take into account that PHP variables are case-sensitive!

我從未使用過此功能,也看不出其用途.有人可以向我解釋在何處可以利用此功能作為一種良好做法嗎?

I've never used this functionality and do not see the purpose for that. Could someone explain to me where this functionality could be exploited as a good practise?

推薦答案

有時我們需要極其靈活且可以參數化的軟件.當然,您必須準備整個事情,但其中一部分只是來自用戶輸入,我們沒有時間僅僅因為用戶需要新輸入而更改軟件.

Sometimes we need software that is extremely flexible and that we can parametrize. You have to prepare the whole thing, of course, but part of it just comes from user input, and we have no time to change the software just because the user needs a new input.

使用可變變量和可變函數,您可以解決沒有它們就更難解決的問題.

With variable variables and variable functions you can solve problems that would be much harder to solve without them.

$comment = new stdClass(); // Create an object

$comment->name = sanitize_value($array['name']);
$comment->email = sanitize_values($array['email']);
$comment->url = sanitize_values($array['url']);
$comment->comment_text = sanitize_values($array['comment_text']);

帶有可變變量

$comment = new stdClass(); // Create a new object


foreach( $array as $key=>$val )
{
    $comment->$key = sanitize_values($val);
}

這篇關于PHP 中的變量 - 它們的目的是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 欧美日韩精品久久久免费观看 | www国产成人免费观看视频,深夜成人网 | 久久午夜精品 | 久久久久久综合 | 日本在线视频一区二区 | 人人叉 | 久久久av中文字幕 | 国内精品久久久久久 | 视频一区二区中文字幕 | 亚洲va欧美va天堂v国产综合 | av一区二区三区在线观看 | 久久久久国产一区二区三区四区 | 国产农村妇女毛片精品久久麻豆 | 中文字幕欧美在线观看 | 91九色在线观看 | 久久久久久99 | 四虎免费视频 | www精品美女久久久tv | 91精品观看 | 夜夜干夜夜操 | 亚洲成人久久久 | 99精品视频在线观看免费播放 | 99pao成人国产永久免费视频 | 久久51 | 尤物在线| 国产精品视频一区二区三区四区国 | www.久久久| 自拍偷拍第一页 | 蜜桃视频一区二区三区 | 一级片视频免费 | 四虎在线播放 | 国产日韩精品一区 | 美日韩视频| 精品在线一区 | 欧美一区二区在线观看视频 | 久久蜜桃av一区二区天堂 | 精品国产一区二区在线 | 日本中文在线视频 | 一级欧美黄色片 | 国产网站在线免费观看 | 国产一区二区在线观看视频 |