@ 2022-08-25T08:26:42Z <?php
$array = [
'tableData' => [
[
'booking_name' => 'abc/xyz/123',
'pdg' => 'assure',
'user_area' => 'es st',
'release' => 'oss72',
'start_date' => '2017-06-20 00:00:00',
'end_date' => '2017-06-23 00:00:00',
'asset_info' => [
[
'status' => 10,
'manufacturer' => 'HP',
'model' => 'HP BL460C GEN8',
'hardware_color' => ''#0066b3'
]
],
'full_name' => 'Valay Desai',
'email_address' => 'valay@xyz.com'
],
[
'booking_name' => 'abc/xyz/123',
'pdg' => 'assure',
'user_area' => 'ls reca',
'release' => 'oss72',
'start_date' => '2017-06-20 00:00:00',
'end_date' => '2017-06-23 00:00:00',
'asset_info' => [
[
'status' => 10,
'manufacturer' => 'SUN',
'model' => 'SUN GEN8',
'hardware_color' => '#0066b3'
]
],
'full_name' => 'Chako Desai',
'email_address' => 'chako@xyz.com'
]
]
];
$filterBy = [
'booking_name' => 'abc',
'pdg' => [
['name' => 'Invalid', 'value' => 'Invalid'],
['name' => 'assure', 'value' => 'assure']
],
'user_area' => [
['name' => 'es st', 'value' => 'es st'],
['name' => 'Invalid', 'value' => 'Invalid'],
['name' => 'a&o', 'value' => 'a&o']
]
];
// simplify structure
$filterBy['pdg'] = array_column($filterBy['pdg'], 'value');
$filterBy['user_area'] = array_column($filterBy['user_area'], 'value');
var_export(
[
'tableData' =>
array_filter(
$array['tableData'],
function($row) use($filterBy) {
return str_contains($row['booking_name'], $filterBy['booking_name'])
&& in_array($row['pdg'], $filterBy['pdg'])
&& in_array($row['user_area'], $filterBy['user_area']);
}
)
]
);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.1 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 array (
'tableData' =>
array (
0 =>
array (
'booking_name' => 'abc/xyz/123',
'pdg' => 'assure',
'user_area' => 'es st',
'release' => 'oss72',
'start_date' => '2017-06-20 00:00:00',
'end_date' => '2017-06-23 00:00:00',
'asset_info' =>
array (
0 =>
array (
'status' => 10,
'manufacturer' => 'HP',
'model' => 'HP BL460C GEN8',
'hardware_color' => '',
),
),
'full_name' => 'Valay Desai',
'email_address' => 'valay@xyz.com',
),
),
) Output for 7.4.0 - 7.4.33 Fatal error: Uncaught Error: Call to undefined function str_contains() in /in/4paXE:67
Stack trace:
#0 [internal function]: {closure}(Array)
#1 /in/4paXE(70): array_filter(Array, Object(Closure))
#2 {main}
thrown in /in/4paXE on line 67
Process exited with code 255 . preferences:dark mode live preview
141.99 ms | 401 KiB | 121 Q