• 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

"Mixed content blocked" when running an HTTP AJAX operation in an HTTPS page

Add customer email and phone in "Order" column to admin orders list on Woocommerce

Woocommerce Edit Message "An account is already registered with your email address. Please log in."

Using array_intersect on a multi-dimensional array

How to change the app environment at run time?

Converting array to string and then back in PHP

Laravel Sanctum CSRF not authenticating

wp_remote_get() not passing authentication

how to use extended ASCII instead of unicode in PHP

PHP Find Array Index value in multi-line array

PHP: set a (deep) array key from an array [closed]

How to make Canonicals with PHP

PHP: convert all UTF-8 characters to HTML entities

Handling expired token in Laravel

Exception thrown during the rendering of a template("Parameter "id" for route "url" must match "[^/]++" ("" given) to generate a corresponding URL.")

About Contact Privacy policy Terms and conditions