Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
429 views
in Technique[技术] by (71.8m points)

php - array merge recursive with eloquent data laravel

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

question from:https://stackoverflow.com/questions/65622977/array-merge-recursive-with-eloquent-data-laravel

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...