我想知道如何限制要显示的数组的值。假设我$color
的等于Indigo
我尝试通过它来实现此代码不起作用
foreach($data as $item){
if($item['color'] == $color){
echo $item['size'].'-'.$item['color'].'-'.$item['price'].'<br>';
}
}
如果我if statement
删除var_dump($data)
array(16) {
[0]=>
array(3) {
["size"]=>
string(1) "2"
["price"]=>
string(6) "$59.00"
["color"]=>
string(11) "Black Rinse"
}
[1]=>
array(3) {
["size"]=>
string(1) "2"
["price"]=>
string(6) "$59.00"
["color"]=>
string(6) "Indigo"
}
[2]=>
array(3) {
["size"]=>
string(1) "4"
["price"]=>
string(6) "$59.00"
["color"]=>
string(11) "Black Rinse"
}
[3]=>
array(3) {
["size"]=>
string(1) "4"
["price"]=>
string(6) "$59.00"
["color"]=>
string(6) "Indigo"
}
[4]=>
array(3) {
["size"]=>
string(1) "6"
["price"]=>
string(6) "$59.00"
["color"]=>
string(11) "Black Rinse"
}
[5]=>
array(3) {
["size"]=>
string(1) "6"
["price"]=>
string(6) "$59.00"
["color"]=>
string(6) "Indigo"
}
[6]=>
array(3) {
["size"]=>
string(1) "8"
["price"]=>
string(6) "$59.00"
["color"]=>
string(11) "Black Rinse"
}
[7]=>
array(3) {
["size"]=>
string(1) "8"
["price"]=>
string(6) "$59.00"
["color"]=>
string(6) "Indigo"
}
[8]=>
array(3) {
["size"]=>
string(2) "10"
["price"]=>
string(6) "$59.00"
["color"]=>
string(11) "Black Rinse"
}
[9]=>
array(3) {
["size"]=>
string(2) "10"
["price"]=>
string(6) "$59.00"
["color"]=>
string(6) "Indigo"
}
[10]=>
array(3) {
["size"]=>
string(2) "12"
["price"]=>
string(6) "$59.00"
["color"]=>
string(11) "Black Rinse"
}
[11]=>
array(3) {
["size"]=>
string(2) "12"
["price"]=>
string(6) "$59.00"
["color"]=>
string(6) "Indigo"
}
[12]=>
array(3) {
["size"]=>
string(2) "14"
["price"]=>
string(6) "$59.00"
["color"]=>
string(11) "Black Rinse"
}
[13]=>
array(3) {
["size"]=>
string(2) "14"
["price"]=>
string(6) "$59.00"
["color"]=>
string(6) "Indigo"
}
[14]=>
array(3) {
["size"]=>
string(2) "16"
["price"]=>
string(6) "$59.00"
["color"]=>
string(11) "Black Rinse"
}
[15]=>
array(3) {
["size"]=>
string(2) "16"
["price"]=>
string(6) "$59.00"
["color"]=>
string(6) "Indigo"
}
}
我只想显示颜色等于的值$color
。我应该如何以正确的方式做到这一点?