PHPackages                             sevens/vars - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sevens/vars

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sevens/vars
===========

Simple Variable library Package For Encoding and Manipulating Strings and Arrays.

v1.1.0(4y ago)1963MITPHPPHP &gt;=7.2.0CI failing

Since Nov 14Pushed 4y ago1 watchersCompare

[ Source](https://github.com/temmyscope/vars)[ Packagist](https://packagist.org/packages/sevens/vars)[ RSS](/packages/sevens-vars/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (3)

About SevenVars
---------------

[](#about-sevenvars)

```
=> Simple Variable library Package For Validating, Encoding and Manipulating Strings and Arrays.

=> Seven Vars is developed by Elisha Temiloluwa a.k.a TemmyScope

=> Seven Vars is a library that comes with a Validation Class,
Arrays Manipulation Class and Strings Generation, Encoding, Sanitization & Manipulation Class

=> The Arrays library of the SevenVars Package implements the Countable,
ArrayAccess & Serializable interface(s) of the Standard PHP Library and provides
you a plethora of methods to manipulate an array of arrays i.e. a level II deep array.

=> The Strings Class allows developers encode, manipulate, sanitize and generate truly random strings.

=> The Validation Class takes in an array and rules for validating whether the value assigned to each key
in the array is a valid entry.

```

#### Installation

[](#installation)

```
composer require sevens/vars
```

### Usage: Seven\\Vars\\Arrays HOW-TO

[](#usage-sevenvarsarrays-how-to)

***In order for the library to generate expected outputs, initialize with a valid array of arrays.*** ***Completely unit tested***

```
- Valid Input Sample

```

```
$data = [
  [
   'name' => 'Random 1',
   'age' => 24, 'password' => 'gHAST_V43SS',
   'nickname' => 'dick & harry'
  ],
  [
   'name' => 'Random 2',
   'age' => 27, 'password' => 'gHAST0SVSS',
   'nickname' => 'harry'
  ],
  [
   'name' => 'Random 3',
   'age' => 24, 'password' => 'gHASTS*VSS',
   'nickname' => 'dick'
  ],
  [
   'name' => 'Random 4',
   'age' => 21, 'password' => 'gHASTSV#SS',
   'nickname' => 'choudharry'
  ]
];
```

***Note: All methods and operations available to objects of the Countable, ArrayAccess and Serializable interfaces are implemented/declared exactly as defined.***

```
- Initialization

```

```
use Seven\Vars\Arrays;

$arrays = new Arrays($data) || Arrays::init($data): Arrays;
```

```
- Safe Initialization: From an array of objects E.g. Laravel's Collection

```

***You can always use the safe Initialization when you are not sure of what type of data is contained in your array i.e. array of arrays OR array of objects***

```
use Seven\Vars\Arrays;

$arrays = Arrays::safeInit($data): Arrays;
```

```
- Adding an array to the existing arrays

```

```
$arrays->add([
 'name' => 'Random 5',
 'age' => 23,
 'nickname' => 'newbie'
]): Arrays;
```

```
- Merging array of arrays to the existing one

```

```
$arrays->addEach([
 [ 'name' => 'Random 6', 'age' => 22, 'nickname' => 'newb1e'],
 [ 'name' => 'Random 7', 'age' => 28, 'nickname' => 'newb6e']
]): Arrays;
```

```
- Adding an array to each array in the existing array of arrays

```

```
$arrays->addToEach([
 [ 'name' => 'Random 6', 'age' => 22, 'nickname' => 'newb1e'],
 [ 'name' => 'Random 7', 'age' => 28, 'nickname' => 'newb6e']
]): Arrays;
```

```
- Pop off and return the last array

```

```
$arrays->pop(): array;
```

```
- Pop off and return an array containing the last key => value in each array

```

```
$arrays->popEach(): array;
```

```
- Shift off and return the first array

```

```
$arrays->shift(): array;
```

```
- Shift off and return an array containing the first key => value in each array

```

```
$arrays->shiftEach(): array;
```

```
- Sort based on key: sorts the arrays based on the value attached to the passed key
 in ascending order: from smallest to highest

```

```
$arrays->sort('name'): Arrays;
```

```
- Sort based on key: sorts the arrays based on the value attached to the passed key
 in ascending order: from highest to smallest.

```

```
$arrays->sort('name'): Arrays;
```

```
- Sort based on key: sorts the arrays based on the value attached to the passed key
 in ascending order: from highest to smallest.

```

```
$arrays->downSort('name'): Arrays;
```

```
- Last: get the last array from the arrays

```

```
$arrays->last(): array;
```

```
- First: get the first array from the arrays

```

```
$arrays->first(): array;
```

```
- apply a callable on all the arrays using their keys: alias => map()

```

***An array reference will be passed to your callable and your callable must return the array, else all values will be NULL***

```
$arrays->apply(function($array): array{
 $array['age'] = $array['age'] * 2;
 return $array;
}): Arrays;
```

```
- sets a new value for each of the arrays using each of the key -> value pair passed;
if an index is passed, only the key at that array index will be changed

```

```
$arrays->set(array $param, ?int $index = null): Arrays;
```

```
- renames a key in each of the arrays using each of the key -> value pair passed;
* if an index is passed, only the key at that array index will be changed

```

```
$arrays->rename(array $k_v, ?int $index = null): Arrays;
```

```
- delete an array from a collection if it violates a validation rule

```

```
$arrays->validateOrDelete([
 'name'=>[ 'required' => true, 'string' => true],
 'age' => [ 'required' => true, 'numeric' => true]
]);

$arrays->get();
```

```
- concatenates values of a particular key of multiple arrays using the passed
separator and saving it on the new name

```

```
$arrays->concat(array $keys, string $new_name, string $separator = "_"): Arrays;
```

```
- Extract key from the initial array using the key, value pair in the passed argument

```

```
$arrays->extractBy(array $k_v): Arrays;
```

```
- Extracts all the arrays containing the passed key

```

```
$arrays->extractByKey($key): Arrays;
```

```
- Extracts from all the arrays, if it contains the passed key

```

```
$arrays->extractKey($key): array;
```

```
- Excludes all array containing the passed key

```

```
$arrays->excludeByKey(string $key): Arrays;
```

```
- Exclude keys from the initial array using the key, value pair in the passed argument

```

```
$arrays->excludeBy(array $k_v): Arrays;
```

```
- Exclude keys from the initial array

```

```
$arrays->excludeKey(...$keys): Arrays;
```

```
- Returns an array of arrays from the initial array containing only the keys specified in the argument

```

```
$arrays->whiteList(array $whitelist): array;
```

```
- picks out random arrays
* the set size has to be smaller than the total size of the array being processed

```

```
$arrays->random(int $size): array;
```

```
- search the value in a key if it contains a certain string

```

```
$arrays->searchFor(mixed $search, string $key): array;
```

```
- Returns an array of arrays from the initial array containing only arrays that
values matching those of the keys specified in the argument;

```

```
$arrays->search(array $k_v): array;
```

```
- Returns an array of the size and start position specified

```

```
$arrays->trim(int $count, int $start = 0): array;
```

```
- checks if the key exists in at least one of the arrays

```

```
$arrays->exists(string $k): bool;
```

```
- yields a list-like array containing [index, array] like python enumerate method

```

```
$arrays->enumerate(): Generator;
```

```
- Returns the count of arrays

```

```
$arrays->count(): int;
```

```
- checks if the array is empty

```

```
$arrays->isEmpty(): bool;
```

```
- For returning the array at its current state

```

```
$arrays->get();
```

```
- For serializing and unserializing

```

```
$arrays->serialize();

$arrays->unserialize( string $serializedData );
```

```
- Return the arrays as JSON ecoded data

```

```
$arrays->getJson();
```

```
- Return the arrays as an iterable array of objects => equivalent to laravel's collection

```

```
$arrays->getObjects();
```

### Usage: Seven\\Vars\\Strings HOW-TO

[](#usage-sevenvarsstrings-how-to)

***Most methods of this class are static, hence do not require initialization******Non static methods in this class are used for encoding, encryption and decryption***

```
- Initialization & Usage: If you'd be using the encryption & decryption feature, It's essential
you construct the object passing necessary variables

```

```
use Seven\Vars\Strings;

$string = new Strings($alg, $salt, $iv);

$string->encrypt($data);

$string->decrypt($encryptedData);
```

```
- Check for the position of a string in another string

```

```
/**
 * Checks if a string ends with a specific string
 *
 * @param string $value
 * @param string|string[] $end
 * @param bool $ignoreCase
 * @return bool
*/
public static function endsWith(string $value, $end, bool $ignoreCase = false): bool

/**
* Checks if a string starts with a specific string
*
* @param string $value
* @param string|string[] $start
* @param bool $ignoreCase
* @return bool
*/
public static function startsWith(string $value, $start, bool $ignoreCase = false): bool

/**
* Extracts a string from between two strings, the start string and the stop string
* @param string $full
* @param string $start
* @param string $stop
* @param bool $ignoreCase
* @return string
*/
public function between($full, $start, $stop, bool $ignoreCase = true): string

/**
* Checks if a string contains a specific string
*
* @param string $value
* @param string|array $contain
* @param bool $ignoreCase
* @return bool
*/
public static function contains(string $str, $contain, bool $ignoreCase = false): bool

/**
* Checks if a string matches a pattern
*
* @param string $str
* @param string $pattern => regular expression pattern
* @return bool
*/
public static function matchesPattern(string $str, string $pattern): bool
```

```
- For generating truly random strings

```

```
/**
* Returns a very random string over 32 characters in length
* @return string
*/
public static function randToken(): string

/**
* Returns a very random string of fixed length
* @param len
* @return string
*/
public static function fixedLengthToken(int $len): string

/**
* trims string to specified length starting from the specified offset
* It is multibyte
* @param string var
* @param int count
* @return reduced string to the specified length
*/
final public static function limit($var, $count = 2225, $offset = 0)

/**
* Returns a random string with very high entropy due to the specified string;
* It will never return two equal strings
* @param string str
* @return string unique_name
*/
final public static function uniqueId(string $str): string
```

```
- Several other methods to format, remove and fix HTML tags; generate time From string etc.

```

### Usage: Seven\\Vars\\Validation HOW-TO

[](#usage-sevenvarsvalidation-how-to)

***In order for the library to generate expected outputs, always initialize with a valid array.******The library comes in handy when dealing with arrays such as $\_POST, $\_GET etc.***

```
- Initialization

```

```
use Seven\Vars\Validation;

$validation = Validation::init($_POST);

####### OR ########

$data = [
 'name' => 'Random 1',
 'email' => 'random1@mail.com',
 'password' => 'pa33w0rd',
 'site' => 'hybeexchange.com',
 'age' => 24,
 'nickname' => 'dick & harry'
];

$validation = new Validation($data);
```

```
- Validation Rules

```

```
$validation->rules([

 #checks if a value was provided or not
 'name' => [ 'required' => true ],

 #checks if value is a valid email address
 'email' => [ 'email' => true ],

 #checks for minimum and maximum character length
 'password' => [ 'required' => true, 'min' => 8, 'max' => 32 ],

 #checks if value is a valid website address
 'site' => [ 'url' => true ],

 #check if value is a number, then check if it is greater than 17 and less than 60
 'age' => [ 'numeric' => true, 'gt' => 17, 'lt' => '60'],

]);
```

```
- Validation Passed or Failed

```

```
$validation->passed(): bool;
```

```
- Validation Errors

```

***Returns an array containing the first encountered error.*** ***Returns an empty array, if all the validation rules passed successfully***

```
$validation->errors(): array;
```

```
- Then - Catch Syntax from JavaScript ES6

```

***The callable passed into the "Then" method is called if validation passed.*** ***The catch method is loaded instead if validation failed.***

***Both Then &amp; Catch accept callables =&gt; closure, array callable, function***

```
$validation->rules([

])->then(function(){
#This callable is called only when valiidations pass
})->catch(function($errors){
#This callable is called only the validation fails
});
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~309 days

Total

2

Last Release

1700d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cf893b3c72ae784c606d4040b4acaaee4aca61dc275641467985023cbd5a7332?d=identicon)[temmyscope](/maintainers/temmyscope)

---

Top Contributors

[![temmyscope](https://avatars.githubusercontent.com/u/16116067?v=4)](https://github.com/temmyscope "temmyscope (52 commits)")

---

Tags

stringencryptdecryptencodearray manipulator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sevens-vars/health.svg)

```
[![Health](https://phpackages.com/badges/sevens-vars/health.svg)](https://phpackages.com/packages/sevens-vars)
```

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[hashids/hashids

Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers

5.5k48.6M278](/packages/hashids-hashids)[cybercog/laravel-optimus

An Optimus bridge for Laravel. Id obfuscation based on Knuth's multiplicative hashing method.

192564.1k](/packages/cybercog-laravel-optimus)[christian-riesen/base32

Base32 encoder/decoder according to RFC 4648

13331.8M61](/packages/christian-riesen-base32)[opis/string

Multibyte strings as objects

7120.9M7](/packages/opis-string)[phootwork/lang

Missing PHP language constructs

1224.8M8](/packages/phootwork-lang)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
