$betarr = [
[
'id' => 1,
'planid' => 1,
'win' => 1,
'return' => 20
],
[
'id' => 2,
'planid' => 2,
'win' => 1,
'return' => 20
],
[
'id' => 3,
'planid' => 3,
'win' => 2,
'return' => 0
], [
'id' => 4,
'planid' => 4,
'win' => 1,
'return' => 20
]
];
var_dump($betarr);
$planbatch = [];
foreach ($betarr as $v) {
$plantmp['id'] = $v['planid'];
$win = (int)$v['win'];
if ($win == 1) {
$plantmp['remainnum'] = $v['return'];
$txffcbetplaninfo = TxffcbetplanModel::loadById($v['planid']);
$remain = (int)$txffcbetplaninfo->remain;
if ($remain == 0) {
$plantmp['remain'] = 0;
$plantmp['status'] = 2;
} else {
';
$plantmp['remain'] = $remain;
$plantmp['status'] = 1;
}
} else {
$plantmp['remainnum'] = 0;
$plantmp['remain'] = 0;
$plantmp['status'] = 2;
}
$planbatch[] = $plantmp;
}
var_dump($planbatch);
如果在else里面不加
$plantmp['remain'] = $remain;
$plantmp['status'] = 1;
那么如果从win=2的开始后面里面的一维数组都会自动补上