PHP code example of sevens / vars

1. Go to this page and download the library: Download sevens/vars library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sevens / vars example snippets


$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'
  ]
];

use Seven\Vars\Arrays;

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

use Seven\Vars\Arrays;

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

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

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

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

$arrays->pop(): array;

$arrays->popEach(): array;

$arrays->shift(): array;

$arrays->shiftEach(): array;

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

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

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

$arrays->last(): array;

$arrays->first(): array;

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

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

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

$arrays->validateOrDelete([
 'name'=>[ 'c' => true]
]);

$arrays->get();

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

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

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

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

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

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

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

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

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

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

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

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

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

$arrays->enumerate(): Generator;

$arrays->count(): int;

$arrays->isEmpty(): bool;

$arrays->get();

$arrays->serialize();

$arrays->unserialize( string $serializedData );

$arrays->getJson();

$arrays->getObjects();

use Seven\Vars\Strings;

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

$string->encrypt($data);

$string->decrypt($encryptedData);


/**
 * 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





/**
* 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


use Seven\Vars\Validation;

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

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

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

$validation = new Validation($data);



$validation->rules([

 #checks if a value was provided or not
 'name' => [ '

 #checks for minimum and maximum character length
 'password' => [ ' less than 60
 'age' => [ 'numeric' => true, 'gt' => 17, 'lt' => '60'],

]);


$validation->passed(): bool;

$validation->errors(): array;

$validation->rules([

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