• 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

How to use React Router with Laravel?

Unit (real unit test) of test laravel relationship

Server-sent events in PHP (without echo or print)

Laravel no logout option from menu after successfull login

php code to send checkbox form results to email

Laravel Model save() & update() Not Saving

Xdebug can't connect back to Docker host

CSV to PHP class properties

using random function but it's displaying duplicates

The "client_reference_id" argument is not passed

Dropzone: Submit both form data and dropzone at once

Laravel print last executed SQL query with Query log

How to install PHP composer inside a docker container

How to modify CSS in a specific page of the WP admin dashboard (backend)

Convert PHP array into HTML tag attributes separated by spaces

About Contact Privacy policy Terms and conditions