How to initialize an associative array with key names and empty values in PHP

1 Answer

0 votes
$arr = array_fill_keys(array('key1', 'key2', 'key3', 'key4'), '');

print_r($arr);



/*
run:

Array
(
    [key1] => 
    [key2] => 
    [key3] => 
    [key4] => 
)

*/

 



answered Jul 12, 2023 by avibootz
...