如何将一个数组值依赖于另一个数组值

时间:2015-09-21 13:00:51

标签: php arrays

我有两个数组, 即

Array ( 
[0] => Sony Xperia Modern Silver 
[1] => Sony Xperia C Purple 
[2] => Sony Xperia C3 Starry Black 
[3] => Sony Xperia C3 Snow White 
[4] => Sony Xperia C3 Fresh Mint 
[5] => Sony Xperia C4 Dual Mint 
[6] => Sony Xperia C4 Dual White 
[7] => Sony Xperia C4 Dual Black);

And

Array ( 
[0] => 40 
[1] => 40 
[2] => 60 
[3] => 40 
[4] => 40 
[5] => 80 
[6] => 80 
[7] => 100);

所以在这种情况下,NAME的第一个数组和%的评论的第二个数组, 我的第一个数组值是如何取决于第二个数组的条件,因为当我们给出条件如if(review> = 60)时我们需要数据(即产品名称)。 在这里,我需要的输出是相关名称是fetch,其审查大于或等于60,记录是降序(记录是降序取决于该perticuler的评论)

1 个答案:

答案 0 :(得分:0)

<?
$ProductName[]=Array ( 
[0] => Sony Xperia Modern Silver 
[1] => Sony Xperia C Purple 
[2] => Sony Xperia C3 Starry Black 
[3] => Sony Xperia C3 Snow White 
[4] => Sony Xperia C3 Fresh Mint 
[5] => Sony Xperia C4 Dual Mint 
[6] => Sony Xperia C4 Dual White 
[7] => Sony Xperia C4 Dual Black);

And

$Reviews[]=Array ( 
[0] => 40 
[1] => 40 
[2] => 60 
[3] => 40 
[4] => 40 
[5] => 80 
[6] => 80 
[7] => 100);

$j=sizeof($ProductName);

for($i=$j;$i>0;$i--) //For descending order
{
    if($Reviews[$i]>=60)
    {
        echo $ProductName[$i]."<br>";
    }
}
?>