PHP code example of kozz / array-updater

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

    

kozz / array-updater example snippets


  $source = ['this' => ['is' => ['the' => ['path' => [
    1,2,3,4,5
  ]]]]];
  
  $array = 
    ArrayUpdater::from($source)
    ->node('this')->node('is')->node('the')->node('path')->all()
    ->replace(1, 100);
  
  /**
   * $array = ['this' => ['is' => ['the' => ['path' => [
   *   100,2,3,4,5
   * ]]]]];
   */
  

  $source = ['this' => [
    ['the' => ['path' => [
      1,2,3,4,5
    ]]],
    ['the' => ['path' => [
      1,2,3,4,5
    ]]]
  ]];
  
  $array = 
    ArrayUpdater::from($array)
    ->node('this')->all()->node('the')->node('path')->all()
    ->replaceAssoc([1=>100, 3=>300]);
  
  /**
   *
   * $array = ['this' => [
   *  ['the' => ['path' => [
   *    100,2,300,4,5
   *  ]]],
   *  ['the' => ['path' => [
   *    100,2,300,4,5
   *  ]]]
   * ]];
   */
   *