PHP 8.3.21 Released!

Voting

: five minus one?
(Example: nine)

The Note You're Voting On

tom p
19 years ago
If you store a string of keys in a database field and want to match them to a static array of values, this is a quick way to do it without loops:

<?

$vals = array("Blue","Green","Pink","Yellow");
$db_field = "0,2,3";

echo implode(", ", array_flip(array_intersect(array_flip($vals), explode(",", $db_field))));

// will output "Blue, Pink, Yellow"

?>

<< Back to user notes page

To Top