drnk.me/utils/arrays.php

11 lines
250 B
PHP
Raw Normal View History

2023-11-29 21:17:08 +00:00
<?php
function &array_get_or_add($needle, array &$haystack, $default=null) {
if (key_exists($needle, $haystack)) {
return $haystack[$needle];
} else {
$haystack[$needle] = $default;
return $haystack[$needle];
}
}