/**
* iaReMapKeys
*
* Maps rowIn[$inKey] to rowsKeyed[$key] using header row to define the mapping.
*
* @notes
* default fills col if: not in read row, or it in read row ==='' || row === null
* rows and headers read are trimmed
*
* @version 1.0.4
*
* @example ../ia_examples/iaReMapKeys.php
*
*//**
* 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
*//**
*
* Sets up mapping rawRow to keyedRow based on $headerRow, fills $this->rowKey2Key
*
* @param array $headerRow
* @return bool has duplicate headers true
*//**
* Return a list of duplicated headers
*
* @return array with duplicated headers ['headerRowKey'=>'label duplicated']
*//**
* Return array mapping header row's keys to desired (wantHeaders)
*
* @return array ['headerRowKey' => 'want header', ..]
*//**
* Returns missing headers in header row, even those with defaults
*
* @return array header keys missing even if the have default values ['missingKeyN',...]
*//**
* Returns missing headers in header row and without default values
*
* @return array header keys missing and without default values ['missingKeyN',...]
*//**
* 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', ...]
*//**
* 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
*//**
* 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,...]
*//**
* Keys missing, null or ''
*
* @param array $rowKeyed
* @return array keys missing or with null, '' values ie ['a','b']
*/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: | |
|
/// 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 | |
|
$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']
|
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]);
|