我有一个遍历数组的foreach循环,并以雄辩的方式保存数据.它是这样的:
foreach($questions['questions'] as $question) {
$questionObject = Question::create([
'external_id' => $question['id'],
'text' => $question['question_text'],
'type' => $question['question_type'],
'image' => (array_key_exists('question_image', $question)) ?
$question['question_image'] : ''
]);
}
Run Code Online (Sandbox Code Playgroud)
但是当我添加if条件时我得到未定义的变量问题错误.
foreach($questions['questions'] as $question) {
if(!$question = Question::where('id', $question['id'])->where(
function($query){
$query->where('updated_at','<', $question['updated']);
}})->first()) {
$questionObject = Question::create([
'external_id' => $question['id'],
'text' => $question['question_text'],
'type' => $question['question_type'],
'image' => (array_key_exists('question_image', $question)) ?
$question['question_image'] : ''
]);
} else {
return 'Question: '.$question['external_id'].' already exist.';
}
}
Run Code Online (Sandbox Code Playgroud)
如果有任何可以帮助我,非常感谢,提前谢谢!
我有一个如下所示的数组:
\n\narray:6 [\xe2\x96\xbc\n 0 => 2\n 1 => 2\n 2 => 2\n 6 => 5\n 10 => 3\n 11 => 1\n]\nRun Code Online (Sandbox Code Playgroud)\n\n我想检查一系列数字,例如 0 到 11,如果这些键存在于我的数组中。如果不是,我想创建缺少键的元素并为其赋予值 0。
\n\n所以我最终会得到一个像这样的数组:
\n\narray:6 [\xe2\x96\xbc\n 0 => 2\n 1 => 2\n 2 => 2\n 3 => 0\n 4 => 0\n 5 => 0\n 6 => 5\n 7 => 0\n 8 => 0\n 9 => 0\n 10 => 3\n 11 => 1\n]\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试过这样的事情:
\n\n$range = range(0,11);\n\nforeach($myArray as $key => $value){\n if(!in_array($key, …Run Code Online (Sandbox Code Playgroud) 我有这种雄辩的查询,我需要从表中随机抽取行,并有限制,但它返回错误,当我使用限制时,它只提取一行,无论我将什么数字作为限制。当我不使用限制时,它会返回随机行数。不知道我错过了什么。这是代码。
$questions = $query->whereRaw('RAND()')->take($limit)->get();
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我有一个离子应用程序,我在其中显示视频,当我在chrome浏览器和android设备上对其进行测试时,效果很好,但是在iPhone上什么也没显示。这是我的html代码:
<iframe ng-show="article.external_media.length > 0 && article.external_media.url != ''" ng-src="{{article.external_media[0].url | safeUrl }} "></iframe>
Run Code Online (Sandbox Code Playgroud) 我在项目中使用打字稿和反应,并且创建了一个简单的组件,我想在其中映射列表并创建反应元素:
const FlightSchedule: React.FC<{ flightRoute: List<Entity<FlightLeg>> }> = ({flightRoute}) => flightRoute.map(route =>
<DescriptionList key={route.get('flightId')}>
<TermDescriptionGroup description={route.get('flightId')}/>
<TermDescriptionGroup description={route.get('flightDate')} topMargin/>
</DescriptionList>)
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下打字稿错误:
Type 'List<Element>' is missing the following properties from type 'ReactElement<any, any>': type, props, key
Run Code Online (Sandbox Code Playgroud)
为什么我会收到此错误,我在这里做错了什么?
laravel ×2
php ×2
angularjs ×1
arrays ×1
eloquent ×1
foreach ×1
iframe ×1
ios ×1
php-closures ×1
reactjs ×1
typescript ×1
video-player ×1