Informática Asociada ia doc & examples Index Examples List

ia\Lib\iaReMapKeys

Change from csv,xls headers to desired array keys

Documentation jit ia\Lib\iaReMapKeys Documentation Usage sample Function examples Index Examples List

class ia\Lib\iaReMapKeys


Index Documentation Usage sample Function examples Index Examples List

ia\Lib\iaReMapKeys


Usage sample ia\Lib\iaReMapKeys Documentation Usage sample Function examples Index Examples List

ia\Lib\iaReMapKeys
Cambia los keys de un array

Setup:

$headerWant = ['a', 'b', 'c', 'z']; $headerSynonim = ['la a' => 'a', 'es a' => 'a', 'la b' => 'b',]; $headerDefault = ['c' => 'default C']; $mapRows = new iaReMapKeys($headerWant, $headerSynonim, $headerDefault);

Header:

  • Row with headers: Array ( [0] => x [1] => a [2] => NO [3] => la b [4] => y )
  • Mapped: Array ( [a] => 1 [b] => 3 )
  • Missing Defaulting Missing: Array ( [0] => z )
  • Missing Without Defaults: Array ( [0] => c [1] => z )
/// set header row $headerRow = ['x', 'a', 'NO', 'la b', 'y']; $hasDuplicatedHeaders = $mapRows->mapHeaderRow($headerRow); // false [1 => 'a', 3 => 'b'] /// Are there missing headers? $headersMissing = $mapRows->getHeaderMissing( ); // ['z'] general: ['missing key 1 and no default',] or []

Remap each row

  • Read row: Array ( [0] => xSoy [1] => aSoy [2] => ySoy [3] => bSoy )
  • Keyed Row: Array ( [c] => default C [a] => aSoy [b] => bSoy )
  • is Keyed Row empty: false
  • Keyed Row missing keys: Array ( [0] => z )
$row=['xSoy', 'aSoy', 'ySoy', 'bSoy']; $rowKeyed = $mapRows->row2key($row); // ['a' => 'aSoy' 'b' => 'bSoy' 'c' => 'default c'] $rowEmpty = $mapRows->isLastRowEmpty(); // false $rowMissingKeys = $mapRows->getRowKeysMissing($rowKeyed); // ['z']

Examples by function ia\Lib\iaReMapKeys Documentation Usage sample Function examples Index Examples List

ia\Lib\iaReMapKeys
Change from csv,xls headers to desired array keys

Disclaimer: Auto generated file. Please help us setting parameters to useful values and extending the examples.

/**
     * Maps rowIn[$inKey] to rowsKeyed[$key] using header row to define the mapping
     *
     * @param array $headerKeys ['key1', 'key2', ...]
     * @param array $headerSynonyms ['Synonym1_1'=>'key1', 'Synonym1_2'=>'key1', 'Synonym2_1'=>'key2', ...] default []
     * @param array $defaultByKey ['key2'=>defaultValueKey2,...] default []
     * @return void
     */
/*
 $iaReMapKeys = new iaReMapKeys(array $headerKeys, array $headerSynonyms = [], array $defaultByKey = []);
*/

$iaReMapKeys = new iaReMapKeys(['a' => '1', 'b' => '2', 'c' => 3]);

  • $iaReMapKeys->mapHeaderRow(array $headerRow) : bool
    /**
         *
         * Sets up mapping rawRow to keyedRow based on $headerRow, fills $this->rowKey2Key
         *
         * @param array $headerRow
         * @return bool has duplicate headers true
         */
    
    1. $iaReMapKeys->mapHeaderRow(['a' => '1', 'b' => '2', 'c' => 3]); -> false
  • $iaReMapKeys->getHeadersDuplicated() : array
    /**
         * Return a list of duplicated headers
         *
         * @return array with duplicated headers ['headerRowKey'=>'label duplicated']
         */
    
    1. $iaReMapKeys->getHeadersDuplicated(); -> 
      Array
      (
      )
      
  • $iaReMapKeys->getHeaderMap() : array
    /**
         * Return array mapping header row's keys to desired (wantHeaders)
         *
         * @return array ['headerRowKey' => 'want header', ..]
         */
    
    1. $iaReMapKeys->getHeaderMap(); -> 
      Array
      (
          [1] => a
          [2] => b
          [3] => c
      )
      
  • $iaReMapKeys->getHeaderMissing() : array
    /**
         * Returns missing headers in header row, even those with defaults
         *
         * @return array header keys missing even if the have default values ['missingKeyN',...]
         */
    
    1. $iaReMapKeys->getHeaderMissing(); -> 
      Array
      (
      )
      
  • $iaReMapKeys->getHeaderMissingWithoutDefaults() : array
    /**
         * Returns missing headers in header row  and without default values
         *
         * @return array header keys missing and without default values ['missingKeyN',...]
         */
    
    1. $iaReMapKeys->getHeaderMissingWithoutDefaults(); -> 
      Array
      (
      )
      
  • $iaReMapKeys->row2key(array $rawRow) : array
    /**
         * Returns $rowKeyed values in $rawRow mapped to headersKey, missing keys (not set, null, '') are filled with defaults
         *
         * @param array $rawRow ['valueForKey1','valueForKey2','valueWithOutKey',]
         * @return array ['key1'=>'valueForKey1', ...]
         */
    
    1. $iaReMapKeys->row2key(['a' => '1', 'b' => '2', 'c' => 3]); -> 
      Array
      (
          [1] => 1
          [2] => 2
          [3] => 3
      )
      
  • $iaReMapKeys->isLastRowEmpty() : boolean
    /**
         * Returns false if last processed row has Data for headers, else true. Ignores defaults
         *
         * @return boolean true: last read row has no values for headersMapped ie is empty (not considering default values),
         *         false has Data for all headers
         */
    
    1. $iaReMapKeys->isLastRowEmpty(); -> 
  • $iaReMapKeys->getRowKeysMissing(array $rowKeyed) : array
    /**
         * Returns missing keys from $rowKeyed, defaulted keys not considered missing
         *
         * @param array $rowKeyed
         * @return array header keys missing, and without defaults, in $rowKeyed ['missingKey1'=>n1,...]
         */
    
    1. $iaReMapKeys->getRowKeysMissing(['a' => '1', 'b' => '2', 'c' => 3]); -> 
      Array
      (
          [0] => 1
          [1] => 2
          [2] => 3
      )
      
  • $iaReMapKeys->getRowKeysEmpty(array $rowKeyed) : array
    /**
         * Keys missing, null or ''
         *
         * @param array $rowKeyed
         * @return array keys missing or with null, '' values ie ['a','b']
         */
    
    1. $iaReMapKeys->getRowKeysEmpty(['a' => '1', 'b' => '2', 'c' => 3]); -> 
      Array
      (
          [0] => 1
          [1] => 2
          [2] => 3
      )
      

End: ia\Lib\iaReMapKeys Documentation Usage sample Function examples Index Examples List