Oihana PHP

toStrings.php

Table of Contents

Functions

toStrings()  : array<int, string>
Filters a value down to a list of strings, keeping every string and integer and dropping the rest.

Functions

toStrings()

Filters a value down to a list of strings, keeping every string and integer and dropping the rest.

toStrings(mixed $value) : array<int, string>

The value is first passed through toArray() (a bare scalar is wrapped as a single-element list), then walked : string and int items are kept, cast to string ; anything else (float, bool, null, arrays, objects, resources) is dropped.

Parameters
$value : mixed

The value to filter — an array, or a bare scalar wrapped via toArray().

Tags
example
use function oihana\core\arrays\toStrings;

toStrings( [ 'a' , 1 , 2.5 , null , 'b' ] ) ; // [ 'a' , '1' , 'b' ]
toStrings( 'solo' )                         ; // [ 'solo' ]
toStrings( null )                           ; // []
author

Marc Alcaraz (ekameleon)

since
1.3.0
Return values
array<int, string>

The kept items, cast to string, re-indexed from 0.

On this page

Search results