3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Test { private static $data = []; public static function Set($key, $value) { static::$data[$key] = $value; } public static function Get($key) { return static::$data[$key]; } } class TestTrait { use Test; public function __construct(){} public function setArrayValues(array $array) { foreach ($array as $key => $value) { Test::Set($key, $value); } } public function getArrayValueFromKey(array $array) { foreach ($array as $key => $value) { var_dump(Test::Get($key)); } } } $songs = [ 'Burial' => 'God is an Astronaut', 'Hazard' => 'Long Distance Calling', 'An Infinite Regression' => 'Animals as Leaders', ]; $testTrait = new TestTrait(); $testTrait->setArrayValues($songs); $testTrait->getArrayValueFromKey($songs);

preferences:
62.96 ms | 402 KiB | 5 Q