反轉字符串是最基本的字符串操作之一,開發人員和程序員經常使用它。 PHP帶有內置函數來反轉字符串。
strrev()函數是PHP中的內置函數,用於反轉字符串。此函數不會更改作為參數傳遞給它的原始字符串。
Synatx:
string strrev($inpString)
參數:該函數接受單個參數$inpString。此參數是一個字符串,它指定我們要反轉的字符串。如果將數字(而不是字符串)傳遞給它,則它還將反轉該數字。
返回值:strrev()函數返回反向的字符串或數字。它不會對參數中傳遞的原始字符串或數字進行任何更改。
例子:
Input : $string = "geeks" Output : skeeg Input : $string = 143 Output : 341
以下示例程序旨在說明PHP中的strrev()函數:
程序1:PHP程序,用於在傳遞字符串時演示strrev()函數。
<?php
// PHP program to demonstrate the
// strrev() function when a string is passed
$str = "geeks";
// prints the reversed string
echo strrev($str);
?>
輸出:
skeeg
程序2:PHP程序,用於在傳遞數字時演示strrev()函數。
<?php
// PHP program to demonstrate the
// strrev() function when a number is passed
// passing number instead of string
$num = 134;
// prints the reversed number
echo strrev($num);
?>
輸出:
431
參考:
http://php.net/manual/en/function.strrev.php
相關用法
- p5.js nfs()用法及代碼示例
- p5.js nfp()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- PHP cos( )用法及代碼示例
- p5.js nf()用法及代碼示例
- PHP tan( )用法及代碼示例
- p5.js nfc()用法及代碼示例
- PHP sin( )用法及代碼示例
- PHP pow( )用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- d3.js d3.set.has()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
注:本文由純淨天空篩選整理自Striver大神的英文原創作品 PHP | strrev() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。