# @php-北京-God\_Ruffianod\_Ruffian

**URL:** <https://www.shiqidu.com/t/topic/207>\
**Category:** 开发调优\
**Tags:** PHP\
**Created:** [2017 年8 月 13 日 15:40 UTC](https://www.shiqidu.com/t/topic/207 "2017-08-13T15:40:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2017 年8 月 13 日 15:40 UTC](https://www.shiqidu.com/t/topic/207/1 "2017-08-13T15:40:01Z")

</div>

```php
asort($a);
function sliceNumber($arr)
{
    $temp = 0;
    $result = [];
    foreach ($arr as $k => $v){
        if ($temp < 20000){
            $arr1[$k] = $v;
            $temp += $v;
            if ($temp > 20000){
                unset($arr1[$k]);
                $arr2[$k] = $v;
            }
        }else{
            $arr2[$k] = $v;
        }
    }
    if (isset($arr1)){
        array_push($result, $arr1);
    }
    if (isset($arr2)){
        array_push($result, $arr2);
    }
    return $result;
}

$res = sliceNumber($a);

var_dump($res);

```

![7c8a48fad16b5fcc1e0e8c11a1878bc8.png](https://discourse.shiqidu.com/uploads_nj/article/20170813/7c8a48fad16b5fcc1e0e8c11a1878bc8.png)

---

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2017 年8 月 13 日 15:40 UTC](https://www.shiqidu.com/t/topic/207/2 "2017-08-13T15:40:32Z")

</div>

是不是这个意思？就两个数组？
