Oihana PHP

betweenParentheses.php

Table of Contents

Functions

betweenParentheses()  : string
Encapsulates an expression between parentheses (`()`).

Functions

betweenParentheses()

Encapsulates an expression between parentheses (`()`).

betweenParentheses([mixed $expression = '' ][, bool $useParentheses = true ][, string $separator = ' ' ][, bool $trim = true ]) : string
  • If the expression is a string, it is wrapped in parentheses.
  • If the expression is an array, its values are concatenated with the given separator, then wrapped in parentheses.
  • If $useParentheses is false, the expression is returned without wrapping.
Parameters
$expression : mixed = ''

The expression to wrap.

$useParentheses : bool = true

Whether to apply the parentheses.

$separator : string = ' '

Separator for arrays.

$trim : bool = true

Whether to trim existing $left/$right characters (default: true).

Tags
example
betweenParentheses( 'sum: 10' ) ;       // '(sum: 10)'
betweenParentheses( ['a', 'b', 'c'] ) ; // '(a b c)'
betweenParentheses( 'val', false ) ;   // 'val'
author

Marc Alcaraz

since
1.0.6
Return values
string

The wrapped expression.


        
On this page

Search results