Oihana PHP

key.php

Table of Contents

Functions

key()  : string
Returns a transformed key by optionally prepending a prefix.

Functions

key()

Returns a transformed key by optionally prepending a prefix.

key(string $key[, string|null $prefix = '' ][, string $separator = '.' ]) : string

This function allows you to prefix a key string with another string, separated by a custom separator. If the prefix is empty or null, the original key is returned unchanged.

Parameters
$key : string

The key to transform.

$prefix : string|null = ''

Optional prefix to prepend. Default is an empty string.

$separator : string = '.'

The separator to use between the prefix and key. Default is '.'.

Tags
example
use function oihana\core\strings\key;

key('name');                  // Returns 'name'
key('name', 'doc');           // Returns 'doc.name'
key('name', 'doc', '::');     // Returns 'doc::name'
key('name', 'doc', '->');     // Returns 'doc->name'
key('name', '');              // Returns 'name'
key('name', null);            // Returns 'name'
author

Marc Alcaraz

since
1.0.0
Return values
string

The transformed key. If prefix is provided, returns "prefix{separator}key", otherwise returns the original key.


        
On this page

Search results