我有這個示例 php 陣列
Data = [
[0] => array [
year=> '2020-01',
data1 => 100,
data2 => 101,
data3 => 102,
],
[1] => array [
year=> '2020-02',
data1 => 200,
data2 => 201,
data3 => 202,
],
[2] => array [
year=> '2020-03',
data1 => 300,
data2 => 301,
data3 => 302,
]
[3] => array [
year=> '2020-04',
data1 => 400,
data2 => 401,
data3 => 402,
]
]
有了這個輸入請求
$request1='2020-01';
$request2='2020-03';
我想獲取 $request1 和 $request2 之間的年份的資料,就像這樣
$result = [
[0] => 100
[1] => 101
[2] => 102
[3] => 200
[4] => 201
[5] => 202
[6] => 300
[7] => 301
[8] => 302
]
這是我的 php-laravel 代碼:
$result = array();
for($i=0;$i<=(($request1-$request2) 1);$i ){
$result[] = Data::select('*')->where('year', '==' ,[$request1,$request2])->get();
}
dd($result);
預期的結果與我想要的不一樣,請幫忙,謝謝
uj5u.com熱心網友回復:
你可以試試這個代碼
$data[] = Data::select('*')->whereBetween('month', [$request1,$request2])->get();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/506720.html
上一篇:Laravel例外:1366不正確的字串值:'\\xC0\\xA7\\xC0\\xA2%2...'列'user_agent'
