• 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

carbon generated datetime not stored correctly into the database

CodeIgniter extend CI_URI undefined method

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given [duplicate]

Limit WooCommerce products in cart only from one custom taxonomy

WHERE IN array binding in DB::raw laravel 5.4

Error Class "LaravelFortifyFeatures" not found

Send Outlook 2010 email using PHP

How do I refresh a DIV content?

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

Combining a describing and one array with data

array_map triple dimensional array [duplicate]

Yii2 select2 database exception number of bound variables does not match number of tokens

Can't call javascript alert alertify library from PHP

AJAX call fails with SyntaxError: Unexpected end of JSON input

Limit login attempts in Laravel 5.7

About Contact Privacy policy Terms and conditions