PHP code example of chris-kruining / utilities

1. Go to this page and download the library: Download chris-kruining/utilities 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/ */

    

chris-kruining / utilities example snippets


CPB\Utilities\Collections\Collection::from([ 'these', 'are', null, null, 'some', null, 'test', 'values', null ])
  ->filter()
  ->toString(' ');

'these are some test values'

join(' ', array_filter([ 'these', 'are', null, null, 'some', null, 'test', 'values', null ]));

CPB\Utilities\Collections\Collection::from([ 'these', '', '', 'are', null, 'some', null, 'test', '', 'values', '' ])
  ->filter(fn($v) => $v !== null && strlen($v) > 0)
  ->map(fn($k, $v) => $k . '::' . $v)
  ->toString('|');

'0::these|1::are|2::some|3::test|4::values'

$filtered = array_filter(
  [ 'these', '', '', 'are', null, 'some', null, 'test', '', 'values', '' ], 
  fn($v) => $v !== null && strlen($v) > 0
);

join('|', array_map(fn($k, $v) => $k . '::' . $v, array_keys($filtered), $filtered));