• 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

laravel automatically deletes server.php on php artisan serve

Symfony there are no commands defined in the "make" namespace

How to auto populate preferredCountries from intl-tel-input with db output

Assets not referencing to public folder (Laravel)

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

Cant seem to get the Pagination to work on my WooCommerce REST API application?

insert multiple rows in a saveall in cakephp

How to average columns of data from multiple, flat arrays?

What is the function of the (new Date()).getTime() in PHP?

Load a .env file with PHP

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

How to skip cart page on woocomerce for certain products only?

PHP cURL (SSL certificate problem: self signed certificate in certificate chain)

array_key_exists(): The first argument should be either a string or an integer

Facebook API, get page post link (PHP)

About Contact Privacy policy Terms and conditions