PHP code example of ntlab / php-obj

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

    

ntlab / php-obj example snippets


  

  use NTLAB\Object\PHP;

  $a = new PHP([1, 2, 3], ['inline' => true]);
  echo (string) $a; // [1, 2, 3]

  $a = new PHP(['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...'], ['inline' => true]);
  echo (string) $a; // ['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...']
  

  

  use NTLAB\Object\Annotation;

  $a = new Annotation(['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...'], ['annotation' => '@Fruit', 'inline' => true]);
  echo (string) $a; // @Fruit(name="Apple", color="Red", description="It's yummy...")
  

  

  use NTLAB\Object\JS;

  $a = new JS(['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...'], ['inline' => true]);
  echo (string) $a; // {name: 'Apple', color: 'Red', description: 'It\'s yummy...'}
  

  

  use NTLAB\Object\YAML;

  $a = new YAML(['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...']);
  echo (string) $a;
  // name:
  //     Apple
  // color:
  //     Red
  // description:
  //     It's yummy...