• 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 to remove index.php and index from the URL using htaccess | PHP

PHP: PDO + CSV export not downloading (headers issue?)

PHP array, move keys and values to new array, but mix it up

Substitute integers and dots with regex [duplicate]

How to make a foreign key not using primary key

Saving Data from form to database using AngularJS and php

Why does codeigniter & Linux server throws unserialize() session data error when user tries to login

how to identify the web server name of remote host

laravel controller function parameters

SendGrid: Sending an email to multiple recipients without other emails being shown on the "to" field

Phpunit partial mock + proxy Entity

PHP using str_starts_with for array to exclude same as with wildcard

How to delete old images from public folder on update using Laravel

How to convert binary string to normal string in php

Hide email address with stars (*)

About Contact Privacy policy Terms and conditions