• 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

Return new collection without modifying original collection

phplaravel-5collectionseloquent


PHP Snippet 1:

$original = collect([1, 2, 3, 4, 5]);

$modified = $original->map(function ($el) {
     return $el * 2; 
});

dd($modified);

PHP Snippet 2:

=> Illuminate\Support\Collection {#3726
     all: [
       2,
       4,
       6,
       8,
       10,
     ],
   }

PHP Snippet 3:

dd($original);

PHP Snippet 4:

=> Illuminate\Support\Collection {#3743
     all: [
       1,
       2,
       3,
       4,
       5,
     ],
   }

Related Snippets

Cross-Origin Resource Sharing (CORS) witth Laravel and Vuejs

How to get the total hour from starting time to end time in php

Laravel 5.1 Unknown database type enum requested

PHPUnit gives error: Target [IlluminateContractsViewFactory] is not instantiable

Laravel Excel::store file empty after stored

Transfer data between JavaScript and PHP through JSON

ORA-12546: TNS:permission denied error connection to remote oracle server

PHP Sorting - getting 10, 11, 12 ... 1, 20, 2 rather than 1, 10, 11, 12 ... 2, 20

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in

Add Class in html Dynamically in PHP

Mysqli Output to a table

Telegram bot doesn't answer

Change user role if checkout custom checkbox is checked in WooCommerce

Convert regular text to array using notepad++

Why do I have invalid argument supply for foreach in Laravel for json response? [duplicate]

About Contact Privacy policy Terms and conditions