http_build_query()函數是PHP中的內置函數,用於從關聯(或索引)數組生成URL編碼的查詢字符串。
用法:
string http_build_query( $query_data, $numeric_prefix, $arg_separator, $enc_type = PHP_QUERY_RFC1738 )
參數:該函數接受上述和以下所述的四個參數:
- $query_data:此參數保存包含以下屬性的數組或對象:
- 它可以是一維數組或多維數組。
- 如果$query_data是對象,則僅將公共屬性合並到結果中。
- $numeric_prefix:如果在基本數組中使用了數字索引,則使用此參數,它將僅在基本數組中元素的數字索引之前。
- $arg_separator:它用於分隔參數,但可以通過指定此參數來覆蓋它。
- $enc_type:其默認值為PHP_QUERY_RFC1738。
返回值:它返回URL編碼的字符串。
以下示例程序旨在說明PHP中的http_build_query()函數:
程序1:
<?php
$info = array(
'sudo' => 'placement',
'CPP' => 'course',
'FORK' => 'C',
);
echo http_build_query($info) . "#";
echo http_build_query($info, '', '&');
?>
輸出:
sudo=placement&CPP=course&FORK=C#sudo=placement&CPP=course&FORK=C
程序2:
<?php
$info = array('geeks', 'gfg' => 'sudo', 'placement' => 'hypertext processor');
echo http_build_query($info) . "$";
echo http_build_query($info, 'myvar_');
?>
輸出:
0=geeks&gfg=sudo&placement=hypertext+processor$myvar_0=geeks&gfg=sudo&placement=hypertext+processor
參考: http://docs.php.net/manual/da/function.http-build-query.php
相關用法
- p5.js nfc()用法及代碼示例
- p5.js nfp()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- p5.js nfs()用法及代碼示例
- PHP cos( )用法及代碼示例
- PHP sin( )用法及代碼示例
- p5.js nf()用法及代碼示例
- PHP tan( )用法及代碼示例
- PHP pow( )用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- d3.js d3.set.has()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
注:本文由純淨天空篩選整理自Code_Mech大神的英文原創作品 PHP | http_build_query() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。