• 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

How do I truncate a decimal in PHP?

How to remove Deprecated SymfonyComponentDebugDebugClassLoader?

Jquery DataTables: Data not displaying in table via Ajax

How to reset Laravel AuthManager/guards in between API calls in tests?

Laravel Get Days In Month From Month Number?

mysql slow on updates for a well optimized query

Laravel Delete and Update

PHP: Print caught exception like Xdebug

Coinpayments create_transaction "ERROR: Invalid command!"

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

Laravel lang slug in url

PHP Startup Unable to load dynamic library /usr/lib/php/20151012/php_mysqli.dll

Laravel 5 session not persisting after user is logged in

disable two buttons after clicking another button

Reload parent page after submit in iframe

About Contact Privacy policy Terms and conditions