• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Laravel database insert with combining array and string

phplaravelpostgresql


PHP Snippet 1:

<?php
$attendanceList = [18354012,18354013,18354014,18354015];
$present = "FALSE";

$insertData = array_map(
    fn($el)=>['id'=>$el, 'present'=>$present],
    $attendanceList
);

$db::table("attendance")->insert($insertData); 

PHP Snippet 2:

foreach ($attendanceList as $id) {
    DB::table("attendance")->insert(["id" => $id,"present" => $present]);
}

Related Snippets

str_word_count() function doesn't display Arabic language properly

MOODLE: What does it mean to aggregate h5p assets?

Check If array is null or not in php

How can I format this number correctly using PHP?

PHP, how to convert Int value to Week days

Open a popup box after receiving result from ajax

printing all running session variable in laravel 5.1

How to validate Envato Purchase Code in PHP

Add restriction to WooCommerce coupons by allowed user ID

I need to link Google Sheet with my Laravel

best way to store error messages in Laravel (session or variable)

Symfony there are no commands defined in the "make" namespace

HTTP Range requests with php for Video Embedding for solving going to specific time in video (seek bar not work)

How to load Codeigniter 4 lang file into an array variable

Laravel 5.5 change unauthenticated login redirect url

About Contact Privacy policy Terms and conditions