Reputation: 3485
So this is an example:
Array (
[0] => Array ( [title] => Title_1 [checkout] => 1 [no_gateway] => 0 )
[1] => Array ( [title] => Title_2 [checkout] => 1 [no_gateway] => 1 )
[2] => Array ( [title] => Title_3 [checkout] => 0 [no_gateway] => 0 )
[3] => Array ( [title] => Title_4 [checkout] => 1 [no_gateway] => 1 )
[4] => Array ( [title] => Title_5 [checkout] => 0 [no_gateway] => 0 )
[5] => Array ( [title] => Title_6 [checkout] => 1 [no_gateway] => 0 )
)
I need to print out all values under [title] key having [checkout] => 1 & [no_gateway] => 0
In my case it should looks like
Please help php-beginner :) Thanks!
Upvotes: 3
Views: 185
Reputation: 97805
print_r(
array_map(function ($a) { return $a["title"]; },
array_filter($original,
function ($a) { return $a["checkout"] && !$a["no_gateway"]; }
)
)
);
Upvotes: 3
Reputation: 44104
foreach( $array as $value ) {
if( $value["checkout"] == 1 && $value["no_gateway"] == 0 ) {
print $value["title"].PHP_EOL;
}
}
Upvotes: 2
Reputation: 1841
You tagged the question with the answer: foreach
// assuming $arr is the array containing the values from the example
foreach ($arr as $record) {
if ($record['checkout'] && !$record['no_gateway']) {
echo $record['title'], "\n";
}
}
Upvotes: 2
Reputation: 42350
foreach ($items as $item) {
if($item['checkout'] == 1 && $item['no_gateway'] == 0) {
echo $item['title'];
}
}
assuming your array is called $items
Upvotes: 4
Reputation: 18350
foreach($array as $row) {
if ($row['checkout'] && !$row['no_gateway']) {
print $row['title'];
}
}
Upvotes: 9