• 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

IlluminateDatabaseQueryException could not find driver [duplicate]

SendGrid: Sending an email to multiple recipients without other emails being shown on the "to" field

Prestashop cUrl Login

"There is no active transaction" when refreshing database in Laravel 8.0 test

Natural ORDER in Laravel Eloquent ORM

Elasticsearch - Want to sort by field in all indices where that particular field available or not if not then avoid it

Override default Auth routes in Laravel 7

Unable to uninstall brew php from homebrew

Detect a fetch request in PHP

Wordpress 'post_type_link' hides permalink

send email using gmail-api and google-api-php-client

Fatal error: Array callback has to contain indices 0 and 1

How to keep value of selected value after form submission?

MySQL - Connection failed: No route to host

How to pass security cloudflare server with php curl

About Contact Privacy policy Terms and conditions