Parkour\Transform::normalize PHP Method

normalize() public static method

Makes every value that is numerically indexed a key, given $default as value.
public static normalize ( array $data, mixed $default ) : array
$data array Data.
$default mixed Default value.
return array Normalized values.
    public static function normalize(array $data, $default)
    {
        $normalized = [];
        foreach ($data as $key => $value) {
            if (is_numeric($key)) {
                $key = $value;
                $value = $default;
            }
            $normalized[$key] = $value;
        }
        return $normalized;
    }

Usage Example

 /**
  *
  */
 public function testNormalize()
 {
     $data = ['one', 'two' => 'three', 'four'];
     $default = 'default';
     $expected = ['one' => $default, 'two' => 'three', 'four' => $default];
     $this->assertEquals($expected, Transform::normalize($data, $default));
 }