首页
开发手册
应用中心
工具
用户中心
FoundPHP Encapsulation function
English
中文简体
English
上一篇
下一篇
###FoundPHP Encapsulation function FoundPHP The encapsulation method is relatively simple. We provide users with encapsulation suggestions and ideas. Encapsulation methods can be placed in the global **plugin/function/globals.php** below the file. If it is encapsulated separately, you can create your own function file in ** plugin / function **. All functions are recommended to use lowercase letters, numbers, underscores, and avoid case. **reference resources:** Format file size ```php 1024){ $temp=$size/1024; $result = size_format($temp,$types+1); }else{ $unit='B'; switch($types){case '0':$unit='B';break;case '1':$unit='KB';break;case '2':$unit='MB';break;case '3':$unit='GB';break;case '4':$unit='TB';break;case '5':$unit='PB';break;case '6':$unit='EB';break;case '7':$unit='ZB';break;} $result = sprintf('%.2f',$size).$unit; } echo $result; ?> ``` We can encapsulate it into a function by changing the way ```php 1024){ $temp=$size/1024; return size_format($temp,$types+1); }else{ $unit='B'; switch($types){case '0':$unit='B';break;case '1':$unit='KB';break;case '2':$unit='MB';break;case '3':$unit='GB';break;case '4':$unit='TB';break;case '5':$unit='PB';break;case '6':$unit='EB';break;case '7':$unit='ZB';break;} return sprintf('%.2f',$size).$unit; } } //call $size = 10240; echo size_format($size); ?> ``` This can be called repeatedly