nizomiddin/helper

为php开发者提供的实用函数。

1.0.0 2021-03-10 07:19 UTC

This package is auto-updated.

Last update: 2024-09-10 20:25:15 UTC


README

👋 为php开发者提供的实用函数。 👋

说明书

  • numberFormat() 将数字格式化为带逗号的字符串。123456.1234000 = 123,456.1234
    • 输入参数
      • @param int $number 需要格式化的数字。通常为0
      • @param int $decimal 格式化后的整数部分。通常为2位
      • @param string $decPoint 数字整数和分数部分分隔符。通常为'.'(点)
      • @param string $thousandsSep 千位分隔符。通常为' '(空格)
      • @param bool $removeZero 0(零)是否移除。通常为true
      • @param bool $showZero 0(零)是否显示。通常为true
        例如
      • UIHelper::numberFormat(123456.0098000); // 结果:123,456.01
      • UIHelper::numberFormat(123456.0098000,3,'.',' ',false); // 结果:123,456.010
      • UIHelper::numberFormat(123456.0098000,3,'.',' ',true,false) 结果:123,456.01
    • 输出参数
      • @return string|null。结果返回字符串。
        <?php 
          use Nizomiddin\Helper\UIHelper; 
          echo "<pre>";
          print_r( UIHelper::numberFormat(123456.0098000) ); 
          echo "</pre>";
        ?>
        

        *

        <?php 
          use Nizomiddin\Helper\UIHelper; 
          echo "<pre>";
          print_r( UIHelper::numberFormat(123456.0098000,3,'.',' ',true,false) );  
          echo "</pre>";
        ?>
        
  • arrayToHtmlStringRecursive() 将数组转换为字符串

    • 输入参数
      • @param array $arrayVar 需要转换为字符串的数组
      • @param string $separator 数组索引(key)与值之间的分隔符。通常为' '(空格)
        例如
      • UIHelper::arrayToHtmlStringRecursive($array,' ');
      • UIHelper::arrayToHtmlStringRecursive($model->errors,' > ');
    • 输出参数
      • @return string|null。结果返回字符串。

    *

     ```
     <?php 
       use Nizomiddin\Helper\UIHelper; 
       $array = [
                 'key01'=>'key11',
                 'key02'=>[
                   'key12'=>'key-111',
                   'key22'=>'key-222',
                 ],
                 'key03'=>'key13',
               ];
       echo "<pre>";
       print_r( UIHelper::arrayToHtmlStringRecursive($array,' ') ); 
       print_r( UIHelper::arrayToHtmlStringRecursive($array,', ') ); 
       print_r( UIHelper::arrayToHtmlStringRecursive($array,'<hr>') ); 
       echo "</pre>";
     ?>
     ```
    

☺ ☺ ☺