• 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

WAMP Virtual Host not working

add uri parameter to Route name in laravel

PHP sort array of objects by two properties

Creating Combinations of Elements

Laravel get user data with profile

Laravel websockets AWS EC2 - Connection failed

PHP-Sort array based on another array?

I want to display default profile image if user do not have profile image

Laravel unique validation on multiple columns

Merge key and value of array index [duplicate]

Warning: A non-numeric value encountered

Using PHP to connect to a remote MSSQL database

Smarty if isset

Yii2 redirecting to previous page after login

Add restriction to WooCommerce coupons by allowed user ID

About Contact Privacy policy Terms and conditions