International PHP Conference Munich 2025

Voting

: two plus five?
(Example: nine)

The Note You're Voting On

Ehsan.Chavoshi.com
5 years ago
I wrote this function to recursively replace array keys with array values (flip) and fill values with defined value. it can be used for recursive array intersect functions .

<?php
function array_values_to_keys_r($array, $fill_value = null)
{
$flipped = [];
foreach (
$array as $key => $value) {
if (
is_array($value)) {
$flipped [$key] = array_values_to_keys_r($value);
} else {
$flipped [$value] = $fill_value;
}
}
return
$flipped;
}
?>

<< Back to user notes page

To Top