PHPackages                             marsapp/maphelper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. marsapp/maphelper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

marsapp/maphelper
=================

Assist in processing the related actions of the mapping table.

0.1.0(6y ago)03MITPHPPHP ^7CI failing

Since May 10Pushed 6y agoCompare

[ Source](https://github.com/marshung24/MapHelper)[ Packagist](https://packagist.org/packages/marsapp/maphelper)[ Docs](https://github.com/marshung24/MapHelper)[ RSS](/packages/marsapp-maphelper/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

1. MapHelper
============

[](#1-maphelper)

- Assist in processing the related actions of the mapping table.
- Provide unified data access functions to facilitate sharing throughout the program.

[![Latest Stable Version](https://camo.githubusercontent.com/88cfc86c7fc44ab2f0e214782a12ba24663bb0b6353bb7e284a6cf97381d76b2/68747470733a2f2f706f7365722e707567782e6f72672f6d6172736170702f6d617068656c7065722f762f737461626c65)](https://packagist.org/packages/marsapp/maphelper) [![Total Downloads](https://camo.githubusercontent.com/eb789c28e9c8e1e05198fec5486b84e407b972b8ab27fee68bfa1a6cdddb2900/68747470733a2f2f706f7365722e707567782e6f72672f6d6172736170702f6d617068656c7065722f646f776e6c6f616473)](https://packagist.org/packages/marsapp/maphelper) [![Latest Unstable Version](https://camo.githubusercontent.com/9cb036f4900a2e4b04831235a327799e1b472b81be59bb0200465e29c30f01d6/68747470733a2f2f706f7365722e707567782e6f72672f6d6172736170702f6d617068656c7065722f762f756e737461626c65)](https://packagist.org/packages/marsapp/maphelper) [![License](https://camo.githubusercontent.com/eec1aa74dbf208ead755cbed24a5a1ecbfca884dd5cc9f9acad3f75251346f6f/68747470733a2f2f706f7365722e707567782e6f72672f6d6172736170702f6d617068656c7065722f6c6963656e7365)](https://packagist.org/packages/marsapp/maphelper)

2. Outline
==========

[](#2-outline)

- [1. MapHelper](#1-maphelper)
- [2. Outline](#2-outline)
- [3. Installation](#3-installation)
    - [3.1. Composer Install](#31-composer-install)
    - [3.2. Include](#32-include)
- [4. Usage](#4-usage)
    - [4.1. Example](#41-example)
- [5. API Reference](#5-api-reference)
    - [5.1. init()](#51-init)
    - [5.2. add()](#52-add)
    - [5.3. addRaw()](#53-addraw)
    - [5.4. sort()](#54-sort)
    - [5.5. getMap()](#55-getmap)
    - [5.6. location()](#56-location)
    - [5.7. hasMap()](#57-hasmap)
    - [5.8. mapList()](#58-maplist)

3. Installation
===============

[](#3-installation)

3.1. Composer Install
---------------------

[](#31-composer-install)

```
# composer require marsapp/maphelper

```

3.2. Include
------------

[](#32-include)

Include composer autoloader before use.

```
require __PATH__ . "vendor/autoload.php";
```

4. Usage
========

[](#4-usage)

4.1. Example
------------

[](#41-example)

Namespace use:

```
// Use namespace
use marsapp\helper\mapping\MapHelper;

// Data
$data = [
    ['c_sn' => 'a110', 'u_sn' => 'b1', 'u_no' => 'a001', 'u_name' => 'name1'],
    ['c_sn' => 'a110', 'u_sn' => 'b2', 'u_no' => 'b012', 'u_name' => 'name2'],
];

// Index by
MapHelper::add($data, 'userInfo', ['c_sn', 'u_no']);

// Get name by a110 => a001 => u_name
$name = MapHelper::getMap('userInfo', ['a110', 'a001', 'u_name']);
// $name = name1;
```

5. API Reference
================

[](#5-api-reference)

5.1. init()
-----------

[](#51-init)

Init map cache table.

```
init(string $mapName = null) : MapHelper
```

> Parameters
>
> - array $mapName: Map name for initialize, if value is null, initialize all.
>
> Return Values
>
> - MapHelper

Example :

```
// Use namespace
use marsapp\helper\mapping\MapHelper;

// Clear the Map cache with the specified name, like: userInfo.
MapHelper::init('userInfo');

//Clear all Map cache.
MapHelper::init();
```

5.2. add()
----------

[](#52-add)

Add data to map cache table. Need to specify the processing method.

```
add(array $data, string $mapName, array $indexBy, string $indexType = 'indexBy') : MapHelper
```

> Parameters
>
> - array $data: Raw data, Want to save to map cache.
> - string $mapName: Map name
> - array $indexBy: Index list for grouping
> - string $indexType: Type list: indexBy, groupBy, indexOnly
>
> Return Values
>
> - MapHelper

Example :

```
// Use namespace
use marsapp\helper\mapping\MapHelper;

// Data
$data = [['c_sn' => 'a110', 'u_sn' => 'b1', 'u_no' => 'a001', 'u_name' => 'name1'], ['c_sn' => 'a110', 'u_sn' => 'b2', 'u_no' => 'b012', 'u_name' => 'name2']];

// Store to map cache - Useing indexBy
MapHelper::add($data, 'map1', ['c_sn', 'u_sn'], 'indexBy');
// Get Map data
$result = MapHelper::getMap('map1');
var_export($result);
// Output:
// array (
//   'a110' =>
//   array (
//     'b1' =>
//     array (
//       'c_sn' => 'a110',
//       'u_sn' => 'b1',
//       'u_no' => 'a001',
//       'u_name' => 'name1',
//     ),
//     'b2' =>
//     array (
//       'c_sn' => 'a110',
//       'u_sn' => 'b2',
//       'u_no' => 'b012',
//       'u_name' => 'name2',
//     ),
//   ),
// )

// Store to map cache - Useing groupBy
MapHelper::add($data, 'map2', ['c_sn', 'u_sn'], 'groupBy');
// Get Map data
$result = MapHelper::getMap('map2');
var_export($result);
// Output:
// array (
//   'a110' =>
//   array (
//     'b1' =>
//     array (
//       0 =>
//       array (
//         'c_sn' => 'a110',
//         'u_sn' => 'b1',
//         'u_no' => 'a001',
//         'u_name' => 'name1',
//       ),
//     ),
//     'b2' =>
//     array (
//       0 =>
//       array (
//         'c_sn' => 'a110',
//         'u_sn' => 'b2',
//         'u_no' => 'b012',
//         'u_name' => 'name2',
//       ),
//     ),
//   ),
// )

// Store to map cache - Useing indexOnly
MapHelper::add($data, 'map3', ['c_sn', 'u_sn'], 'indexOnly');
// Get Map data
$result = MapHelper::getMap('map3');
var_export($result);
// Output:
// array (
//   'a110' =>
//   array (
//     'b1' => '',
//     'b2' => '',
//   ),
// )
```

5.3. addRaw()
-------------

[](#53-addraw)

Add raw data to map cache table. Data will be directly stored in cache.

```
addRaw(array $data, string $mapName) : MapHelper
```

> Parameters
>
> - array $data: Raw data, Want to save to map cache.
> - string $mapName: Map name
>
> Return Values
>
> - MapHelper

Example :

```
// Use namespace
use marsapp\helper\mapping\MapHelper;

// Data
$data = [['c_sn' => 'a110', 'u_sn' => 'b1', 'u_no' => 'a001', 'u_name' => 'name1'], ['c_sn' => 'a110', 'u_sn' => 'b2', 'u_no' => 'b012', 'u_name' => 'name2']];

// Store to map cache
MapHelper::addRaw($data, 'map1');
// Get Map data
$result = MapHelper::getMap('map1');
var_export($result);
// Output:
// [['c_sn' => 'a110', 'u_sn' => 'b1', 'u_no' => 'a001', 'u_name' => 'name1'], ['c_sn' => 'a110', 'u_sn' => 'b2', 'u_no' => 'b012', 'u_name' => 'name2']]
```

5.4. sort()
-----------

[](#54-sort)

Sort map data. When doing location point, it is necessary to sort in advance.

```
sort(string $mapName, $type = 'ksort') : MapHelper
```

> Parameters
>
> - string $mapName: Map name
> - string $type: Sort type, Support 'ksort', 'krsort'
>
> Return Values
>
> - Returns the resulting array.

Example :

```
// Use namespace
use marsapp\helper\mapping\MapHelper;

$data = ['1111' => 'name1', '3333' => 'name3', '2222' => 'name2'];

// Add map
MapHelper::addRaw($data, 'testMap');

// Sort Map and output
$result = MapHelper::sort('testMap', 'ksort')->getMap('testMap');
var_export($result);
// Output: ['1111' => 'name1', '2222' => 'name2', '3333' => 'name3']

// Sort Map and output
$result = MapHelper::sort('testMap', 'krsort')->getMap('testMap');
var_export($result);
// Output: ['3333' => 'name3', '2222' => 'name2', '1111' => 'name1']
```

5.5. getMap()
-------------

[](#55-getmap)

Data re-index by keys

```
getMap(string $mapName, array $indexBy = [], $exception = false) : mixed
```

> Parameters
>
> - string $mapName: Map name
> - array $indexBy: Index list for search
> - bool $exception: default false
>
> Throw Exception Return Values
>
> - array|mixed

Example :

```
// Use namespace
use marsapp\helper\mapping\MapHelper;

$data = ['1111' => 'name1', '3333' => 'name3', '2222' => 'name2'];

// Add map
MapHelper::addRaw($data, 'testMap');
$result = MapHelper::getMap('testMap');
var_export($result);
// Output: ['1111' => 'name1', '3333' => 'name3', '2222' => 'name2']
```

5.6. location()
---------------

[](#56-location)

Get data by location point. When doing location point, it is necessary to sort in advance.

```
location(string $mapName, array $indexBy, string $location) : mixed
```

> Parameters
>
> - string $mapName: Map name
> - array $indexBy: array indexs before location point.
> - string $location: Location point field name
>
> Return Values
>
> - mixed

Example :

```
// Use namespace
use marsapp\helper\mapping\MapHelper;

// Data
$data = ['lv1' => ['lv2' => ['2011-05-06' => '11', '2012-01-01' => '12', '2015-09-16' => '15']]];

// Add map
MapHelper::addRaw($data, 'testMap');

// Get data by location point.
$result = MapHelper::location('testMap', ['lv1', 'lv2'], '2011-12-05');
var_export($result);
// Output: 11

// Get data by location point.
$result = MapHelper::location('testMap', ['lv1', 'lv2'], '2012-12-05');
var_export($result);
// Output: 12
```

5.7. hasMap()
-------------

[](#57-hasmap)

Data re-index by keys

```
hasMap(string $mapName) : boolean
```

> Parameters
>
> - array $mapName: Map name.
>
> Return Values
>
> - boolean

Example :

```
// Use namespace
use marsapp\helper\mapping\MapHelper;

// Add map
MapHelper::addRaw([1, 2, 3, 4], 'map1');

// Determine whether the target map table exists
$mapName = 'map1';
if (MapHelper::hasMap($mapName)) {
    echo $mapName . ' Exist.';
} else {
    echo $mapName . ' Not exist.';
}
```

5.8. mapList()
--------------

[](#58-maplist)

Data re-index by keys

```
mapList() : array
```

> Return Values
>
> - array.

Example :

```
// Use namespace
use marsapp\helper\mapping\MapHelper;

// Add map
MapHelper::addRaw([1, 2, 3, 4], 'map1');
MapHelper::addRaw(['a', 'b'], 'map2');

// Get map name list and print it.
$mapList = MapHelper::mapList();
var_export($mapList);
// output: ['map1', 'map2']
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2245d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/34496839?v=4)[MarsHung](/maintainers/marshung24)[@marshung24](https://github.com/marshung24)

---

Top Contributors

[![marshung24](https://avatars.githubusercontent.com/u/34496839?v=4)](https://github.com/marshung24 "marshung24 (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/marsapp-maphelper/health.svg)

```
[![Health](https://phpackages.com/badges/marsapp-maphelper/health.svg)](https://phpackages.com/packages/marsapp-maphelper)
```

###  Alternatives

[copex/vatfix

Magento2 module for accepting VAT's (UID) with country code (ex.ATU69932326) as usual in EU.

1717.9k](/packages/copex-vatfix)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
