• 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

Inserting data into SQL Server Db An Invalid direction was specified

Explain how this array transposing and flattening function works

stay with the last 15 elements of an array [duplicate]

How to properly set "0000-00-00 00:00:00" as a DateTime in PHP

How do I upload a laravel project on cPanel shared hosting?

phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO)

Filter array by skipping every nth element from the end

PHP block shortcut in Visual Studio Code

Magento Installation SQLSTATE[HY000] [2002] No such file or directory error

possible options to create pdf file using html elements to generate invoice in php and codeigniter

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

How to run or debug php on Visual Studio Code (VSCode)

PHP web3 ERC20 token function call

How to break out of a foreach once a condition is met?

Laravel SQL query midnight time not showing

About Contact Privacy policy Terms and conditions