我有2個數組,其中包含單詞和其他字和值。我有下面的代碼將檢查一個數組與另一個數組,並將添加值,並將返回總數。但是,如果字符串中存在常見單詞,代碼也會爲它們添加值。在數組中的PHP特定字
在下面的例子中,我怎麼才能得到確切的單詞Green的值? 像下面的例子中I總應該是3,而不是15
$a_array = array(array("name"=> "Red", "price"=> "2"),
array("name"=> "Green", "price"=> "3"),
array("name"=> "Green Leaf", "price"=> "4"),
array("name"=> "Green Light", "price"=> "8"),
array("name"=> "Grey", "price"=> "1"),
array("name"=> "Yellow", "price"=> "11"));
$check = array(Blue, Green, Black,);
$total = 0; foreach ($check as $key => $value):
foreach ($a_array as $itemKey => $itemValue):
if (strstr($itemValue['name'], $value)):
$total += $itemValue['price'];
continue; endif; endforeach; endforeach;
echo "Total: $total";
請贊成票也。謝謝 – 2016-02-03 07:21:49