- array_map: documentation ( source)
- print_r: documentation ( source)
<?php
class Foo {
private string $foo;
private array $bar;
public function __construct(string $foo, array $bar) {
$this->foo = $foo;
$this->bar = $bar;
}
public function square(): array {
return array_map(fn($x) => $x * $x, $this->bar);
}
}
$foo = new Foo('hello', [1, 2, 3, 4]);
print_r($foo);
print_r($foo->square());