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

x
+
cmd
[
'broken' => 'Broken',
'fake' => 'Fake Products'
]
Advertisements

Demonstration


PHP - Find the array items based on Multiple keys

Previous
Write a PHP Code to find the numbers with less occurance start to finish with number of occurance