数组切片不打印但var_dump确实如此

时间:2015-05-04 20:31:39

标签: php arrays sorting

我正在尝试运行代码但是,它不起作用。

$customerArray[] = [
    'name' => 'Delta Inc',
    'phone'=> '0123456789',
    'spend'=>1,
    'email' => 'info@acme.co.uk',
    'business_type_id'=>1
];
usort($customerArray, function($a, $b) {
    if($a['spend'] == $b['spend']) {
        return 0;
    } else if ($a['spend'] > $b['spend']) {
        return -1;
    } else {
        return 1;
    }
});
/* The top 10 elements are now on top of the array */    
$top = array_slice($customerArray, 0, 10);

/* If we reverse the array using array_reverse() the 
   smallest items are on top */
$low = array_slice(array_reverse($customerArray), 0, 10);

var_dump var_dump('$top')显示数据import itertools xlist = [9, 13, 10, 5, 3] pairs = itertools.combinations(xlist, 2) answer = 0 for pair in pairs: answer += pair[0] * pair[1] 。但是我想要提供查询的结果。

1 个答案:

答案 0 :(得分:1)

试试这个

echo "<pre>";
print_r($top);
echo "</pre>";

此 将遍历数组

foreach ($top AS $value){ 
    echo $value.'<br>' 
}

或者如果你想获得一件物品

echo $top[0];//Gets First item
echo $top[1];//Gets Second item