• 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

laravel automatically deletes server.php on php artisan serve

Entity provider not working in security.yml php symfony3.4 ({"code":401,"message":"bad credentials"}.)

PHP, how to convert Int value to Week days

Pagekite error: FAIL: localhost:8080 is down

How to add a custom field to all Woocommerce attribute terms using add_action

Handling expired token in Laravel

How can I convert from a{a{} b{}} to a[a[],b[]] using php preg_match?

PHP array stringify

Can't find vendor/autoload.php for Ratchet

Laravel php artisan serve to mimic HTTPS

PHPUnit 7: Failed asserting that exception of type InvalidArgumentException is thrown

How to give apache permission to write to home directory?

301 Redirect to remove query string on homepage only

PHP Form Not Inserting

RabbitMQ PRECONDITION_FAILED - unknown delivery tag

About Contact Privacy policy Terms and conditions