• 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

HTML and PHP in one file

Passing a boolean value from checkbox in Laravel form

Laravel Get Days In Month From Month Number?

PHP and WebView - Cookie doesn't are the same

Dropzone: Submit both form data and dropzone at once

IlluminateDatabaseQueryException could not find driver [duplicate]

how to upload binary image to sql server using php laravel

Cannot pass null argument when using type hinting

Laravel 5: Is there a non-case sensitive way to sort a collection by an attribute?

How can I stop a symfony process which is listening on http://127.0.0.1:8000

Access relation of pivot table in Laravel

How to get company posts from LinkedIn via API?

PHP Get value from JSON [duplicate]

Laravel get user data with profile

How to add automatically collapse/expand in content wordpress (single.php)?

About Contact Privacy policy Terms and conditions