• 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

Adding reCAPTCHA v2 into my PHP file

Vimeo API: how to save a vimeo into a subfolder?

php retrieve specific data onclick from database in a list format

Nginx disallowing execution of PHP in uploads directory with Magento

Star rating with half star support

Add restriction to WooCommerce coupons by allowed user ID

codeigniter 4 running error first time with xampp

How to find phpcs current default standard

How to install PHP composer inside a docker container

Laravel Mix Uncaught ReferenceError: $ is not defined

Is it possible to re-use an array taken from PHP via JSON in a $.ajax function?

woocommerce get_order_report_data to show order_item_id

How to get monthly wise data in laravel

xdebug 3 not working in ubuntu 20.04 with docker

How to redirect to another page after n seconds in wordpress without using javascript?

About Contact Privacy policy Terms and conditions