<?php
$array = [
"foo" => "no",
"foo_contact_firstname" => "Mark",
"foo_email" => "mark@gmail.com",
"foo_address1" => "91",
"foo_address2" => "old road",
"foo_bill" => "no",
"bar" => "yes",
"bar_contact_lastname" => null,
"bar_telephone" => null,
"bar_email" => null,
"bar_address1" => null,
"bar_address2" => null,
"bar_address3" => null,
"bar_address4" => null,
"bar_address5" => null,
"bar_postcode" => null,
"register_contact_firstname" => null,
"register_contact_lastname" => null,
"register_telephone" => null,
"register_email" => null,
"register_address1" => null,
"register_address2" => null,
"register_address3" => null,
"register_address4" => null,
"register_address5" => null,
"register_postcode" => null,
];
$test = array_filter($array, function($key) {
return $key == 'foo';
}, ARRAY_FILTER_USE_KEY );
var_dump($test);
- Output for 5.6.38, 7.1.0 - 7.1.23, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
- array(1) {
["foo"]=>
string(2) "no"
}
preferences:
85.49 ms | 407 KiB | 5 Q