• 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

Explode not working properly with dash

PDOException SQLSTATE[HY000] [2002] No such file or directory

Open a popup box after receiving result from ajax

PHP rotate matrix counter-clockwise

dompdf and img tag, image wont show

Updating and Synchronizing Woocommerce Subscriptions to Custom Date

httpd.conf on Windows: can't locate API model structure `php8_module`

Passing PHP JSON to Javascript: echo json_encode vs echo json declaration

Maatwebsite Excel 3.1 : how do I skip duplicate data when imported?

Laravel insert dynamic input values with radio button

Xdebug can't connect back to Docker host

Laravel Pagination links() not working

Normalize DateInterval in PHP

How to increase the PHP upload limits [duplicate]

Upgrade PHP on AWS Linux

About Contact Privacy policy Terms and conditions