• 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

Convert string to lowercase AND then convert it to its original form in PHP, is it possible?

Laravel with App Engine Standard Class 'FacadeIgnitionIgnitionServiceProvider' not found

CodeIgniter force_download is not working

How do I enable error reporting in Laravel?

How to get array values using foreach in laravel

WAMP Virtual Host not working

renameColumn migration fails for existing column with columns does not exist error

Laravel Nova, route not found

Laravel Unknown Column 'updated_at'

Twig - How to check if variable is a number / integer

PhP how to calculate moments with variables rows

Check if a string contain multiple specific words

is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)

How to generate QR CODE for dynamic generating link and logo using Simple QrCode in laravel?

I want to use codeigniter foreign character library in my custom PHP project how i can use it?

About Contact Privacy policy Terms and conditions