So, basically I have this array data:
$data = ['one', 'two', 'three'];
Now, I want to assign a value on each element on that array, that would be something like this:
$val = 'new'; // 'new' value is get from $val $data = [ 'one' => 'new', 'two' => 'new', 'three' => 'new' ];
How did I do that? Thanks.
$data = ['one', 'two', 'three']; $val = 'new'; $newArray = array_fill_keys($data, $val); print_r($newArray);
Fiddle here.
1.4m articles
1.4m replys
5 comments
57.0k users