1. Go to this page and download the library: Download oihana/php-core 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/ */
oihana / php-core example snippets
function oihana\core\strings\camel;
use function oihana\core\strings\fastFormat;
use function oihana\core\arrays\get;
use function oihana\core\accessors\getKeyValue;
use function oihana\core\accessors\setKeyValue;
// Strings
echo camel('hello_world'); // helloWorld
echo fastFormat('Hello {0}', 'World'); // Hello World
// Arrays (dot-notation path)
$profile = ['user' => ['name' => 'Alice', 'city' => 'Paris']];
echo get($profile, 'user.name'); // Alice
// Accessors work with arrays and objects
$doc = (object)['user' => (object)['email' => '[email protected]']];
echo getKeyValue($doc, 'user.email'); // [email protected]
$doc = setKeyValue($doc, 'user.age', 30); // adds nested property safely
use function oihana\core\arrays\get;
use function oihana\core\arrays\flatten;
use function oihana\core\arrays\unique;
$data = ['a' => 1, 'b' => ['c' => 2, 'd' => [3, 4]]];
echo get($data, 'b.c'); // 2
print_r(flatten($data)); // ['a' => 1, 'b.c' => 2, 'b.d.0' => 3, 'b.d.1' => 4]
print_r(unique([1,1,2,3,3])); // [1,2,3]
use function oihana\core\strings\camel;
use function oihana\core\strings\fastFormat;
echo camel('foo-bar_baz'); // fooBarBaz
echo fastFormat('User {0} has {1} points', 'Alice', 1500);
// User Alice has 1500 points
use function oihana\core\objects\compress;
$user = (object)[
'name' => 'John',
'email' => '[email protected]',
'phone' => null,
'address' => ''
];
// Removes all null and empty string values
print_r(compress($user));
/*
stdClass Object
(
[name] => John
[email] => [email protected]
)
*/
use function oihana\core\date\formatDateTime;
echo formatDateTime('2023-10-27 10:00:00', 'Europe/Paris', 'd/m/Y H:i'); // 27/10/2023 10:00
// The default format ends on a literal Z, the ISO-8601 designator for UTC,
// so the moment is converted before being labelled.
echo formatDateTime('2023-10-27T10:00:00+02:00'); // 2023-10-27T08:00:00.000Z