Oihana PHP

map.php

Table of Contents

Functions

map()  : object
Transforms every public property value of an object through a callback.

Functions

map()

Transforms every public property value of an object through a callback.

map(object $object, callable $fn) : object

Returns a new stdClass with the same property names, each value replaced by the result of fn( $value , $key ). The source object is never modified.

Parameters
$object : object

The source object.

$fn : callable

The mapping callback: fn( $value , $key ): mixed.

Tags
example
use function oihana\core\objects\map;

$prices = (object) [ 'a' => 10 , 'b' => 20 ] ;

$result = map( $prices , fn( $v ) => $v * 2 ) ;
// (object) [ 'a' => 20 , 'b' => 40 ]
author

Marc Alcaraz (ekameleon)

since
1.0.9
Return values
object

A new stdClass with mapped values.

On this page

Search results