本文介绍了如何传递变量"$ tid,$ id";转化为原始功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在raw函数中调用$id
和$tid
从mongodb集合的子文档中获取一些数据时,它显示错误these two variables are undefined($tid,$id)
吗?
when i call $id
and $tid
in raw function to fetch some data from sub document of mongodb collection it show me an error these two variables are undefined($tid,$id)
?
<?php
$id=IntValue;
$tId=IntValue;
if($tId==0)
{
$maxPlayers=0;
}
else
{
$result = DB::collection('PrizeDistributionTemplate')->raw(function($collection)
{
return $collection->aggregate(array(
array(
'$match' => array( 'id' => $id,'templates.tId' => $tid)
),
array( '$unwind' => '$templates' ),
array(
'$match' => array( 'id' => $id,'templates.tId' => $tid)
),
));
});
$result=json_decode(json_encode($result),true);
$maxPlayers=$result['result'][0]['templates']['maxPlayers'];
$maxPlayers=intval($maxPlayers)+2;
}
?>
推荐答案
它将与批量添加一起很好地工作,这种方式只需要在数组上创建并传递它即可.
It will work great with bulk addition, this way you just need to create on array and pass it.
$temp = [
[
'item' => "envelopes"
],
[
'item' => "envelopesas"
],
[
'item' => "lala"
]
];
$userData = DB::table('log') - > raw(function ($collection) use($temp)
{
return $collection - > insertMany($temp);
});
这篇关于如何传递变量"$ tid,$ id";转化为原始功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!