• 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

PHP: How to solve ob_start() in combination imagepng() issue?

Where do I need to place a hook for phpunit?

Implode array with array of glue strings

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

How can I easily switch between PHP versions on Mac OSX?

Google API Heatmap Layer exception, why?

Limit login attempts in Laravel 5.7

Find out the name of the last script that included the current one

PHP each() function replacement

Call to undefined function openssl_decrypt

Correctly determine if date string is a valid date in that format

Navigation idle on content download

Select option from dropdown menu with PHP and mySql

php echo remove slashes from url [duplicate]

How can i hide dt if dd got empty value

About Contact Privacy policy Terms and conditions