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.
2.1m questions
2.1m answers
60 comments
56.8k users