public static function flattenAssoc(
    array $kvArray,
    /*string*/ $kField,
    /*string|boolean*/ $vField
  ) {
    $array = [];
    if(!empty($kvArray) && self::isAssoc($kvArray)) {
      foreach($kvArray as $k => $v) {
        $row = [];
        if(is_string($vField)) {
          $row[$vField] = $v;
        } else if(true === $vField && self::isAssoc($v)) {
          // Merge associative array values into row.
          $row = array_merge($row, $v);
        }
        $row[$kField] = $k;
        $array[] = $row;
      }
    }
    return $array;
  }
public static function flattenAssoc(
    array $kvArray,
    /*string*/ $kField,
    /*string|boolean*/ $vField
  ) {
    $array = [];
    if(!empty($kvArray) && self::isAssoc($kvArray)) {
      foreach($kvArray as $k => $v) {
        $row = [];
        if(is_string($vField)) {
          $row[$vField] = $v;
        } else if(true === $vField && self::isAssoc($v)) {
          // Merge associative array values into row.
          $row = array_merge($row, $v);
        }
        $row[$kField] = $k;
        $array[] = $row;
      }
    }
    return $array;
  }
public static function flattenAssoc ( array $ kvArray , /*string*/ $ kField , /*string|boolean*/ $ vField ) { $ array = [ ] ; if ( ! empty ( $ kvArray ) && self :: isAssoc ( $ kvArray ) ) { foreach ( $ kvArray as $ k => $ v ) { $ row = [ ] ; if ( is_string ( $ vField ) ) { $ row [ $ vField ] = $ v ; } else if ( true === $ vField && self :: isAssoc ( $ v ) ) { // Merge associative array values into row. $ row = array_merge ( $ row , $ v ) ; } $ row [ $ kField ] = $ k ; $ array [ ] = $ row ; } } return $ array ; }
Returns a flattened array for the specified associative array. Keys and
values are hosted in a new array, and then inserted as regular rows to be
returned as the result.

@param array $kvArray associative array to flatten
@param string $kField field name for keys
@param string $vField field name for values, or TRUE to flatten the value
when it's an associative array
@return array flattened array (could be empty if original array is empty)
Returns a flattened array for the specified associative array . Keys and values are hosted in a new array and then inserted as regular rows to be returned as the result .