PHP code example of northern / common

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

    

northern / common example snippets


use Northern\Common\Util\ArrayUtil as Arr;

$a = array(
   'foo' => 'bar'
);

$value = Arr::get( $a, 'foo' );

// $value == 'bar'

$value = Arr::get( $a, 'baz', NULL );

// $value == NULL

$a = array(
   'foo' => array(
      'bar' => array(
         'baz' => 123
      )
   )
);

$value = Arr::get( $a, 'foo.bar.baz' );

// $value == 123

$value = Arr::getPath( $a, 'foo/bar/baz', NULL, '/' );

// $value == 123

$a = array();

Arr::set( $a, 'foo.bar.baz', 123 );

// $a = array( 'foo' => array( 'bar' => array( 'baz' => 123 ) ) );

$a = array();

Arr::set( $a, 'foo.bar.baz', 123 );

Arr::insert( $a, 'foo.bar.baz', 123 );

// The insert statement does nothing.

Arr::delete( $a, 'foo.bar.baz' );    

Arr::delete( $a, array('fum', 'foo.bar.baz', 'foo.bar.bob') );

Arr::delete( $a, array('fum', 'foo/bar/baz', 'foo/bar/bob'), '/' );

$value = Arr::exists( $a, 'foo.bar.baz' );

// $value == TRUE

$a = array('1', '2', '3');

$values = Arr::prefix( $a, '$' );

// $values = array('$1', '$2', '$3');

$a = array('1', '2', '3');

$values = Arr::postfix( $a, '$' );

// $values = array('1$', '2$', '3$');

$a = array('param1' => '123', 'param2' => 'xyz');

$values = Arr::flatten( $a );

// $values = array('param1=123', 'param2=xyz');

$values = Arr::flatten( $a, '|' );

// $values = array( 'param1|123', 'param2|xyz' );

$a = array('param1' => '123', 'param2' => 'xyz');

$values = Arr::keys( $a, '&' );

// $values = array( '&param1', '&param2' )

$a = array('param1' => '123', 'param2' => 'xyz');

$values = Arr::values( $a, '&' );

// $values = array( '&123', '&xyz' )

$b = Arr::contains( array('A', 'B'), array('A', 'B', 'C') );

// $b = TRUE

$a = array(
   'foo' => 'bar'
);

$value = Arr::extract( $a, 'foo' );

// $value == 'bar'
// $a = array()