Wednesday, October 21, 2020

PHP array_fill_keys() Function

Hello folks! welcome to another section of our tutorial on PHP. In this tutorial, we will be discussing about array_fill_keys() Function.

PHP array_fill_keys() function fills an array with the value of the value parameter, using the values of the keys array as keys.


Following below is the syntax to use this function -

array array_fill_keys ( array $keys, mixed $value );

Parameter Details

Sr.NoParameter & Description


It is an array of values that will be used as keys



It may an string or an array of values

Return Value

It returns the filled array.


Try out the below example -

   $ = array('f1', 5, 10, 'b1');
   $a = array_fill_keys($input, 'banana');


When the above code is executed, it will produce the following result -

Array (
   [f1] => banana
   [5] => banana
   [10] => banana
   [b1] => banana

Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we are going to be discussing about the PHP array_filter() Function.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.


Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.