gpt4 book ai didi

php - 比较一个数组的值并输出

转载 作者:行者123 更新时间:2023-12-03 23:05:03 24 4
gpt4 key购买 nike

我有一个可以多次包含相同值的数组。我试图找到一种方法来比较该数组内的值并仅输出每个值一次。

$_just_a_tier = array();

foreach ($_associatedProducts as $_item){
// count all products

$_tierprice = $this->getTierPrices($_item);
foreach ($_tierprice as $_ay){
$_tier = $_ay['price_qty'];
// echo $_tier.' | ';

$_just_a_tier[] = $_tier;
}
}

print_r($_just_a_tier);

这将输出例如那:

Array
(
[0] => 36
[1] => 50
[2] => 72
[3] => 108
[4] => 110
[5] => 120
[6] => 144
[7] => 180
[8] => 360
[9] => 540
[10] => 960
[11] => 20
[12] => 30
[13] => 36
[14] => 72
[15] => 108
[16] => 144
[17] => 180
[18] => 360
[19] => 540
)

谢谢。

最佳答案

PHP 中有一个内置函数,名为 array_unique这可以为您解决这个问题。

关于php - 比较一个数组的值并输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3316675/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com