Algorithm
We'll use array_intersect_key()
function of PHP
Code Examples
#1 Code Example with PHP Programming
Code -
PHP Programming
<?php
$all_options = [
'broken' => 'Broken',
'dummy' => 'Dummy',
'fake' => 'Fake Products'
];
$selected_options = ['broken', 'fake'];
$data = array_intersect_key($all_options, array_flip($selected_options));
// [ 'broken' => 'Broken', 'fake' => 'Fake Products' ]
var_dump($data);
Copy The Code &
Try With Live Editor
Output
[
'broken' => 'Broken',
'fake' => 'Fake Products'
]
'broken' => 'Broken',
'fake' => 'Fake Products'
]
Demonstration
PHP - Find the array items based on Multiple keys