original_string: public static function walk(
          array &$array,
          callable $callback,
          $recurse = false,
          $path = '',
          $considerLeaves = true
      ) {
          $path = trim($path, '.');
  
          foreach ($array as $key => $value) {
              if (is_array($value) && $recurse) {
                  if ($considerLeaves === false && !static::hasNested($value)) {
                      $callback($key, $value, $array, $path);
                      continue;
                  }
  
                  $deeperPath = $key;
  
                  if ($path !== '') {
                      $deeperPath = vsprintf('%s.%s', [$path, $key]);
                  }
  
                  static::walk(
                      $array[$key],
                      $callback,
                      true,
                      $deeperPath,
                      $considerLeaves
                  );
                  continue;
              }
  
              $callback($key, $value, $array, $path);
          }
  
          return $array;
      }
code: public static function walk(
          array &$array,
          callable $callback,
          $recurse = false,
          $path = '',
          $considerLeaves = true
      ) {
          $path = trim($path, '.');
  
          foreach ($array as $key => $value) {
              if (is_array($value) && $recurse) {
                  if ($considerLeaves === false && !static::hasNested($value)) {
                      $callback($key, $value, $array, $path);
                      continue;
                  }
  
                  $deeperPath = $key;
  
                  if ($path !== '') {
                      $deeperPath = vsprintf('%s.%s', [$path, $key]);
                  }
  
                  static::walk(
                      $array[$key],
                      $callback,
                      true,
                      $deeperPath,
                      $considerLeaves
                  );
                  continue;
              }
  
              $callback($key, $value, $array, $path);
          }
  
          return $array;
      }
code_tokens: public static function walk ( array & $ array , callable $ callback , $ recurse = false , $ path = '' , $ considerLeaves = true ) { $ path = trim ( $ path , '.' ) ; foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) && $ recurse ) { if ( $ considerLeaves === false && ! static :: hasNested ( $ value ) ) { $ callback ( $ key , $ value , $ array , $ path ) ; continue ; } $ deeperPath = $ key ; if ( $ path !== '' ) { $ deeperPath = vsprintf ( '%s.%s' , [ $ path , $ key ] ) ; } static :: walk ( $ array [ $ key ] , $ callback , true , $ deeperPath , $ considerLeaves ) ; continue ; } $ callback ( $ key , $ value , $ array , $ path ) ; } return $ array ; }
docstring: A more complicated, but flexible, version of `array_walk`.
  
  This modified version is useful for flattening arrays without losing
  important structure data (how the array is arranged and nested).
  
  Possible applications: flattening complex validation responses or a
  configuration file.
  
  Additional features:
  - The current path in dot notation is provided to the callback.
  - Leaf arrays (no nested arrays) can be optionally ignored.
  
  Callback signature:
  ```php
  $callback($key, $value, $array, $path);
  ```
  
  @param array $array
  @param callable $callback
  @param bool $recurse
  @param string $path - The current path prefix.
  @param bool $considerLeaves
  
  @return array
docstring_tokens: A more complicated but flexible version of array_walk .