Skip to content

Instantly share code, notes, and snippets.

@crossmaya
Last active May 8, 2021 01:59
Show Gist options
  • Save crossmaya/5319554 to your computer and use it in GitHub Desktop.
Save crossmaya/5319554 to your computer and use it in GitHub Desktop.

Revisions

  1. crossmaya revised this gist May 8, 2021. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions help.php
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ function updateAppVersion($appVersion1, $appVersion2)
    {
    $len = count($releaseVersion);
    }

    for($i = 0;$i<$len;$i++){
    echo "[i=".$i."][r=".$releaseVersion[$i]."][d=".$deviceVersion[$i]."]";
    if(!isset($releaseVersion[$i])){
    @@ -28,9 +28,7 @@ function updateAppVersion($appVersion1, $appVersion2)
    else if($releaseVersion[$i]<$deviceVersion[$i]){
    return false;
    }

    }

    return false;
    }

  2. crossmaya revised this gist May 8, 2021. No changes.
  3. crossmaya revised this gist May 8, 2021. No changes.
  4. crossmaya revised this gist May 8, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion help.php
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ function updateAppVersion($appVersion1, $appVersion2)
    {
    $len = count($releaseVersion);
    }

    for($i = 0;$i<$len;$i++){
    echo "[i=".$i."][r=".$releaseVersion[$i]."][d=".$deviceVersion[$i]."]";
    if(!isset($releaseVersion[$i])){
  5. crossmaya revised this gist May 8, 2021. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions help.php
    Original file line number Diff line number Diff line change
    @@ -7,9 +7,10 @@ function updateAppVersion($appVersion1, $appVersion2)
    {
    $releaseVersion = explode(".",$appVersion1);
    $deviceVersion = explode(".",$appVersion2);

    $len = count($deviceVersion);
    if(count($releaseVersion)>count($deviceVersion)){
    if(count($releaseVersion)>count($deviceVersion))
    {
    $len = count($releaseVersion);
    }

  6. crossmaya revised this gist May 8, 2021. No changes.
  7. crossmaya revised this gist May 8, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion help.php
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ function updateAppVersion($appVersion1, $appVersion2)
    {
    $releaseVersion = explode(".",$appVersion1);
    $deviceVersion = explode(".",$appVersion2);

    $len = count($deviceVersion);
    if(count($releaseVersion)>count($deviceVersion)){
    $len = count($releaseVersion);
  8. crossmaya revised this gist May 8, 2021. No changes.
  9. crossmaya revised this gist May 8, 2021. No changes.
  10. crossmaya revised this gist May 8, 2021. 1 changed file with 28 additions and 0 deletions.
    28 changes: 28 additions & 0 deletions help.php
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,35 @@
    /** common libs **/

    //应用版本比较
    function updateAppVersion($appVersion1, $appVersion2)
    {
    $releaseVersion = explode(".",$appVersion1);
    $deviceVersion = explode(".",$appVersion2);

    $len = count($deviceVersion);
    if(count($releaseVersion)>count($deviceVersion)){
    $len = count($releaseVersion);
    }

    for($i = 0;$i<$len;$i++){
    echo "[i=".$i."][r=".$releaseVersion[$i]."][d=".$deviceVersion[$i]."]";
    if(!isset($releaseVersion[$i])){
    return false;
    }
    else if(!isset($deviceVersion[$i])){
    return true;
    }
    else if($releaseVersion[$i]>$deviceVersion[$i]){
    return true;
    }
    else if($releaseVersion[$i]<$deviceVersion[$i]){
    return false;
    }

    }

    return false;
    }


    /** Array helper **/
  11. crossmaya revised this gist May 8, 2021. No changes.
  12. crossmaya revised this gist May 8, 2021. No changes.
  13. crossmaya revised this gist May 8, 2021. No changes.
  14. crossmaya revised this gist May 8, 2021. No changes.
  15. crossmaya revised this gist May 8, 2021. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions help.php
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@

    /** common libs **/

    //应用版本比较



    /** Array helper **/

  16. crossmaya revised this gist May 8, 2021. No changes.
  17. crossmaya revised this gist May 8, 2021. No changes.
  18. crossmaya revised this gist May 8, 2021. No changes.
  19. crossmaya revised this gist May 8, 2021. No changes.
  20. crossmaya revised this gist May 8, 2021. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions help.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,8 @@
    <?php

    /** common libs **/


    /** Array helper **/

    function array_except($array, $key)
  21. crossmaya revised this gist Jan 8, 2021. 1 changed file with 156 additions and 0 deletions.
    156 changes: 156 additions & 0 deletions Functions.inc.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,156 @@
    <?php declare(strict_types=1);

    use GuzzleHttp\Client;
    use Swoft\Stdlib\Helper\ArrayHelper;
    use GuzzleHttp\Exception\RequestException;

    /**
    * 数据格式化
    *
    * @access public
    * @param mixed $args 待处理数据
    * @return mixed
    */
    if ( ! function_exists('formatData')) {
    function formatData($args)
    {
    $data = [];

    foreach ($args as $key => $val) {
    $key = lineToHump((string)$key);

    if (is_array($val) || is_object($val)) {
    $val = formatData($val);
    }

    $data[$key] = $val;
    }

    return $data;
    }
    }

    /**
    * 驼峰转下划线
    *
    * @access public
    * @param string $str 字符串
    * @return string
    */
    if ( ! function_exists('lineToHump')) {
    function humpToLine(string $str)
    {
    return preg_replace_callback('/([A-Z])/', function ($match) {
    return '_'.lcfirst($match[0]);
    }, $str);
    }
    }

    /**
    * 下划线转驼峰
    *
    * @access public
    * @param string $str 字符串
    * @return string
    */
    if ( ! function_exists('lineToHump')) {
    function lineToHump(string $str)
    {
    return preg_replace_callback('/(_[a-z])/', function ($match) {
    return ucfirst(trim($match[0], '_'));
    }, $str);
    }
    }

    /**
    * 随机字符串
    *
    * @access public
    * @param integer $len 字符长度
    * @param boolean $int 纯数字
    * @return string
    */
    if ( ! function_exists('random')) {
    function random($len = 10, $int = false)
    {
    $str = '';
    $len = (is_numeric($len)) ? $len : 10;

    $seed = base_convert(md5(microtime(true).uniqid((string)mt_rand(), true)), 16, ( ! empty($int)) ? 10 : 35);
    $seed = ( ! empty($int)) ? (str_replace('0', '', $seed).'012340567890') : ($seed.'zZ'.strtoupper($seed));

    if ( ! empty($int)) {
    $str = '';
    } else {
    $str = chr(mt_rand(1, 26) + mt_rand(0, 1) * 32 + 64);
    --$len;
    }

    $max = strlen($seed) - 1;

    for ($i = 0; $i < $len; ++$i) {
    $str .= $seed{mt_rand(0, $max)};
    }

    return $str;
    }
    }

    /**
    * 发送请求
    *
    * @access public
    * @param string $url URL
    * @param array $args 提交参数
    * @param array $headers HEAD信息
    * @param string $method 提交方法
    * @return array
    * @throws
    */
    if ( ! function_exists('send')) {
    function send(string $url, array $args = [], array $headers = [], string $method = 'POST')
    {
    $status = ['code' => 0, 'data' => [], 'message' => ''];

    try {
    $options = ( ! empty($args)) ? ['form_params' => $args] : [];

    if ( ! empty($headers)) {
    $options['headers'] = $headers;
    }

    $response = (new Client())->request($method, $url, $options);
    $content = $response->getBody()->getContents();

    if (empty($content)) {
    throw new \Exception('没有返回相关数据!');
    }

    $status = ['code' => 200, 'data' => $content, 'message' => ''];
    } catch (RequestException $e) {
    $status['message'] = $e->getMessage();
    }

    return $status;
    }
    }

    /**
    * 格式化JSON
    *
    * @access public
    * @param mixed $data 待处理数据
    * @return mixed
    */
    if ( ! function_exists('withJson')) {
    function withJson(array $data)
    {
    if (isset($data['data'])) {
    if (empty($data['data']) && is_array($data['data'])) {
    $data['data'] = new \stdClass();
    }
    }

    return $data;
    }
    }
  22. crossmaya revised this gist Dec 14, 2017. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions help.php
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,24 @@ function array_except($array, $key)
    return array_diff_key($array, array_flip((array) $key));
    }

    if (! function_exists('objectToArray') )
    {
    function objectToArray($d)
    {
    if( is_object($d) )
    {
    $d = get_object_vars($d);
    }
    if( is_array($d) )
    {
    return array_map(__FUNCTION__, $d);
    } else
    {
    return $d;
    }
    }
    }


    /* String Helper */

  23. crossmaya revised this gist Jun 27, 2013. 1 changed file with 18 additions and 3 deletions.
    21 changes: 18 additions & 3 deletions help.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,14 @@
    <?php
    /** Array helper **/

    function array_except($array, $key)
    {
    return array_diff_key($array, array_flip((array) $key));
    }


    /* String Helper */

    function start_with($haystack, $needle)
    {
    return strpos($haystack, $needle) === 0;
    @@ -10,9 +20,14 @@ function ends_with($haystack, $needle)
    }


    /** Array helper **/
    /* Common Helper */

    function array_except($array, $key)
    function with($object)
    {
    return array_diff_key($array, array_flip((array) $key));
    return $object;
    }

    function value($value)
    {
    return $object instanceof Closure ? $value() : $value;
    }
  24. crossmaya revised this gist Jun 27, 2013. 1 changed file with 9 additions and 7 deletions.
    16 changes: 9 additions & 7 deletions help.php
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,13 @@
    <?php
    function start_with($haystack, $needle) {
    return strpos($haystack, $needle) === 0;
    }

    function ends_with($haystack, $needle){
    return $needle == substr($haystack, strlen($haystack) - strlen($needle));
    }
    function start_with($haystack, $needle)
    {
    return strpos($haystack, $needle) === 0;
    }

    function ends_with($haystack, $needle)
    {
    return $needle == substr($haystack, strlen($haystack) - strlen($needle));
    }


    /** Array helper **/
  25. crossmaya revised this gist Jun 27, 2013. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion help.php
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,12 @@ function start_with($haystack, $needle) {

    function ends_with($haystack, $needle){
    return $needle == substr($haystack, strlen($haystack) - strlen($needle));
    }
    }


    /** Array helper **/

    function array_except($array, $key)
    {
    return array_diff_key($array, array_flip((array) $key));
    }
  26. crossmaya revised this gist Apr 5, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion help.php
    Original file line number Diff line number Diff line change
    @@ -3,4 +3,6 @@ function start_with($haystack, $needle) {
    return strpos($haystack, $needle) === 0;
    }


    function ends_with($haystack, $needle){
    return $needle == substr($haystack, strlen($haystack) - strlen($needle));
    }
  27. crossmaya renamed this gist Apr 5, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  28. crossmaya revised this gist Apr 5, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    <?php
    function start_with($haystack, $needle) {
    return strpos($haystack, $needle) === 0;
    }
    }


  29. crossmaya created this gist Apr 5, 2013.
    4 changes: 4 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    <?php
    function start_with($haystack, $needle) {
    return strpos($haystack, $needle) === 0;
    }