Laravel Miscellaneous Helper Function: data_fill

November 21, 2016 —John Koster

data_fill(&$target, $key, $value)

The data_fill helper function accomplishes the same fundamental task as the data_set helper function. The only difference is that the data_fill does not define an optional $overwrite parameter. data_fill internally makes a call to the data_set (discussed in the Laravel Miscellaneous Helper Function: data_set article) helper function with $overwrite set to false. This function does not overwrite data.

The following function calls are equivalent wand would produce the same results:

1<?php
2 
3// Create a object to work with.
4$testObject = new stdClass;
5 
6// Set data using `data_fill`.
7data_fill($testObject, 'name', 'Jane');
8 
9// Set data using `data_set`.
10data_set($testObject, 'name', 'Jane', false);

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.