hi guys i have trouble working with array merge on laravel, this my data :
<?php use AppHttpModelsTahuns; public function merge(){ $tahun = Tahuns::pluck('tahun'); $value = [1,2,1]; $merge = array_merge_recursive($tahun,$value); return $merge; } output : 0: 2010 1: 2011 2: 2012 ???
i want get output something like this:
0: 0: 2010 1: 1 1: 0: 2011 1: 2 2: 0: 2012 1: 1
can anyone with same experience help? thanks guys
You can try using collection
for example
$value = [1,2,1]; $result = Tahuns::pluck('tahun')->map(function($year, $index) use (value) { return [ $year, $value[$index] ]; })->toArray();
2.1m questions
2.1m answers
60 comments
57.0k users