I want to know how can I limit the values of array to be displayed. Assuming my $color
is equals to Indigo
I tried implementing this code by it doesn't work
foreach($data as $item){
if($item['color'] == $color){
echo $item['size'].'-'.$item['color'].'-'.$item['price'].'<br>';
}
}
And if I remove the if statement
the 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"
}
}
I want only to display values which is the color is equal to $color
. How should I do this the correct way?