ecommit/scalar-values

Test scalar values.

v1.2.0 2024-11-22 16:08 UTC

This package is auto-updated.

Last update: 2024-12-14 15:43:47 UTC


README

Tests

Installation

To install scalar-values with Composer just run :

$ composer require ecommit/scalar-values

Usage

Test if an array contains only scalar values :

use Ecommit\ScalarValues\ScalarValues;

$array = ['str1', 2, 3];
if (ScalarValues::containsOnlyScalarValues($array)) { //True
    //...
} else {
    //...
}

$array = ['str1', ['tab'], 3];
if (ScalarValues::containsOnlyScalarValues($array)) { //False
    //...
} else {
    //...
}

Returns the input array after deleting all non-scalar values (on root):

use Ecommit\ScalarValues\ScalarValues;

$array = ['str1', ['tab'], 3];
$newArray = ScalarValues::filterScalarValues($array); //[0 => 'str1', 2 => 3]

License

This librairy is under the MIT license. See the complete license in LICENSE file.