PHP code example of live-controls / utils

1. Go to this page and download the library: Download live-controls/utils 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/ */

    

live-controls / utils example snippets


$array['val1' => 'Value1', 'val2' => 'Value2'];
echo array_get('val1', $array); // 'Value1'
echo array_get('val3', $array); // null
echo array_get('val3', $array, 'no_value'); // 'no_value'

$array['val1' => 'someValue', 'val2' => 'someOtherValue'];
array_remove('val1', $array);
echo $array; //['val2' => 'someOtherValue']

$array ['someValue', 'someOtherValue'];
array_remove_value('someValue', $array);
echo $array; //['someOtherValue']

$array['someValue', 'someOtherValue'];
echo array_has_duplicates($array); //returns false
$array2['key1' => 'someValue', 'key2' => 'someValue'];
echo array_has_duplicates($array2); //returns true
$array3['1984', 1984];
echo array_has_duplicates($array3, true); //returns false, because type of value 0 is different than from value 1
$array4[1984, 1984];
echo array_has_duplicates($array4, true); //returns true, because type of value 0 and value 1 are identical

$array['someValue', 'someOtherValue'];
echo array_get_duplicates($array); //returns an empty array
$array2['key1' => 'someValue', 'key2' => 'someValue'];
echo array_get_duplicates($array2); //returns an array ['someValue']
$array3['1984', 1984];
echo array_get_duplicates($array3, true); //returns an empty array, because type of value 0 is different than from value 1
$array4[1984, 1984];
echo array_get_duplicates($array4, true); //returns an array [1984], because type of value 0 and value 1 are identical

$text = "This is a text with 400 words [...]"; //Imagine this text as 400 words long
echo estimatedReadingTime($text); //Would return 2 (minutes) as the default words per minute rate is 200
echo estimatedReadingTime($text, 100); //Would return 4 (minutes) as the second parameter of the function acts as words per minute 

$var = 1234;
echo countNumber($var); //'4'

echo calculateDaysInMonth(0,5,11,2022); //returns the days in month as integer

echo number2Text(100, 'pt_BR'); //returns the text representation of the number by its locale

echo leadingZeros(10, 4, false); //returns 0010
echo leadingZeros(10, 1, true); //throws exception because third parameter (isMax) is true and the number has more than 1 digit (second parameter {length})

echo number2Currency(1000.20, 'pt_br', 'USD'); //returns $1.000,20

echo array2String(['a','b','c'], '; '); //returns a; b; c

echo isNullOrEmpty(' '); //returns true

echo toInteger('a1234'); //returns 1234
echo toInteger('a01234'); //IMPORTANT, this would also return 1234 as an integer cant start with 0. In this case use toNumeric()

echo toNumeric('a01234'); //returns a string 01234
echo toNumeric('a1234'); //returns an integer 1234

echo stringContains('Test', 'T'); //returns true
echo stringContains('Test', 'Q'); //returns false

echo isValidCPF('UM_CPF_VALIDO'); //returns true if cpf is valid

echo isValidCNPJ('UM_CNPJ_VALIDO'); //returns true if cnpj is valid

echo toLatin('càdé'); //returns cade

echo importCSV('test.csv'); //returns the content of the file test.csv as array with its first line as header