PHPackages                             arpablue/fieldlist - 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. arpablue/fieldlist

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

arpablue/fieldlist
==================

It is a object to mange a value using a key, but identify each value using uncase-sensitive key. This allow get values using case un-sensitive methods and compare both list, using a strict mode for a exactly comparation of the keys and values, an compare mode only verify the current keys and values aexist in the second luist and the low mode only verify the keys exists in the second list.

v1.0.0(1y ago)09MITPHP

Since May 31Pushed 1y ago1 watchersCompare

[ Source](https://github.com/arpablue/FieldList)[ Packagist](https://packagist.org/packages/arpablue/fieldlist)[ RSS](/packages/arpablue-fieldlist/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

FieldList class
===============

[](#fieldlist-class)

It is a component to manage keys and values using uncase sensitivity, identifying each field with unique keys using the name of the field. This helps to get a value no matter if the key is called, capitalized or not. This object allows you to compare with another list. It is possible to use the SET method only to modify an element or the PUT method to modify an element or add this element if it doesn’t exist in the list.

Install FieldList
-----------------

[](#install-fieldlist)

To install the library it is possible to execute the following command using composer.

*composer require ArpaBlue\\FieldList*

Initialize an FieldList
-----------------------

[](#initialize-an-fieldlist)

To initialize the object is necessary add the reference to the library.

*use **ArpaBlue\\FieldList\\FieldList**;*

To initialize the FieldList is similar to any other objects.

*$**fieldList** = **new** **FieldList**();*

Add elements
------------

[](#add-elements)

To add elements to the list is necessary use the PUT method.

*$list = **new** **FieldList**();*

*$list-&gt;**put**("name","Alan");*

*$list-&gt;**put**("lastname","Brooks");*

*$list-&gt;**put**("email","");*

*$list-&gt;**put**("phone","2223336666");*

*$list-&gt;**put**("age","21");*

Modify an element
-----------------

[](#modify-an-element)

To modify an element we can use two methods.

### PUT method

[](#put-method)

The PUT method can modify a value of a value in the list.

*$**list** = **new** **FieldList**();*

*$**list**-&gt;**put**("name","Alan");*

*$**list**-&gt;**put**("lastname","Brooks");*

*$**list**-&gt;**put**("email","");*

*echo "\\nContains: " . $list; // output -&gt; Contains: {{"name":"Alan"},{"lastname":"Brooks"},{"email":""}}*

*$**list**-&gt;**put**("lastname","Woods");*

*echo "\\nContains: " . $**list**; // output -&gt; Contains: {{"name":"Alan"},{"lastname":"Woods"},{"email":""}}*

*But if the element doesn’t exist then it is added to the list.*

*$**list**-&gt;**put**("phone",2223336666);*

*echo "\\nContains: " . $**list**; // output -&gt; Contains: {{"name":"Alan"},{"lastname":"Woods"},{"email":""},{"phone":2223336666}}*

### SET method

[](#set-method)

*The SET method can modify a value of an element in the list, if the element does not exists in the list then it is not added to the list.*

*use **ArpaBlue\\FieldList\\FieldList**;*

*$**list** = **new FieldList**();*

*$**list**-&gt;**put**("name","Alan");*

*$**list**-&gt;**put**("lastname","Brooks");*

*$**list**-&gt;**put**("email","");*

*echo "\\nContains: " . $**list**; // output -&gt; Contains: {{"name":"Alan"},{"lastname":"Brooks"},{"email":""}}*

*$**list**-&gt;**set**("lastname","silverman");*

*echo "\\nContains: " . $**list**; // output -&gt; Contains: {{"name":"Alan"},{"lastname":"silverman"},{"email":""},{"phone":2223336666}}*

*But if the element doesn’t exist in the list then it isn’t added to the list.*

*$**list**-&gt;**set**("country","England");*

*echo "\\nContains: " . $**list**; // output -&gt; Contains: {{"name":"Alan"},{"lastname":"silverman"},{"email":""},{"phone":2223336666}}*

Class methods
-------------

[](#class-methods)

### ToJSON

[](#tojson)

This method returns the structure of the list as a string with JSON format, this method is used to convert the current list into a string.

*$**list** = **new** **FieldList**();*

*$**list**-&gt;**put**("name","Alan");*

*$**list**-&gt;**put**("lastname","Brooks");*

*$**list**-&gt;**put**("email","");*

*echo "\\nLlist: " . $**list**; // output -&gt; List: {{"name":"Alan"},{"lastname":"Brooks"},{"email":""}}*

### Remove elements

[](#remove-elements)

The class contains 2 methods to remove elements.

#### Remove element

[](#remove-element)

It removes an element specified for the name or key of the field, it is necessary to specify the name or key of the field.

*$list = new **FieldList**();*

*$list-&gt;**put**("name","Alan");*

*$list-&gt;**put**("lastname","Brooks");*

*$list-&gt;**put**("email","");*

*$list-&gt;**put**("phone","3334445555");*

*$list-&gt;**put**("age",21);*

*$**list**-&gt;**removeAll**();*

*echo "\\nList: " . $**list**; // Output -&gt; List: {}*

#### Remove all elements

[](#remove-all-elements)

It removes all elements of the list.

*$**list** = new **FieldList**();*

*$**list**-&gt;**put**("name","Alan");*

*$**list**-&gt;**put**("lastname","Brooks");**$**list**-&gt;**put**("email","");**$**list**-&gt;**put**("phone","3334445555");**$**list**-&gt;**put**("age",21);*

*$**list**-&gt;**remove**("email");*

*echo "\**nList**: " . $**list**; // Output -&gt; List: {{"name":"Alan"},{"lastname":"Brooks"},{"phone":"3334445555"},{"age":21}}\*

### size()

[](#size)

It returns the quantity fields of the current list.

*$**list** = **new** **FieldList**();*

*$**list**-&gt;**put**("name","Alan");*

*$**list**-&gt;**put**("lastname","Brooks");*

*$**list**-&gt;**put**("email","");*

*$**list**-&gt;**put**("phone","3334445555");*

*$**list**-&gt;**put**("age",21);*

*echo "\\nList length: " . $**list**-&gt;**size**(); // output -&gt; List length: 5*

### getNames()

[](#getnames)

It return an array with the names of all the fields.

*list = **new** **FieldList**();*

*$**list**-&gt;**put**("name","Alan"); // position: 0**$**list**-&gt;**put**("lastname","Brooks"); // position: 1**$**list**-&gt;**put**("email",""); // position: 2**$**list**-&gt;**put**("age",21); // position: 3**$**list**-&gt;**put**("phone","3332225555"); // position: 4**$**list**-&gt;**put**("country","Paris"); // position: 5**$**list**-&gt;**put**("language","French"); // position: 6*

*$**names** = $**list**-&gt;**getNames**();*

*print\_r( $**names** );*/\* Ouput: *Array**(**\[0\] =&gt; name**\[1\] =&gt; lastname**\[2\] =&gt; email**\[3\] =&gt; age**\[4\] =&gt; phone**\[5\] =&gt; country**\[6\] =&gt; language**)*\*/

### exists()

[](#exists)

It verify if the a field with the name specified exists.

*$**list** = **new FieldList**();*

*$**list**-&gt;**put**("name","Alan");**$**list**-&gt;**put**("lastname","Brooks");**$**list**-&gt;**put**("email","");**$**list**-&gt;**put**("age",21);**$**list**-&gt;**put**("phone","3332225555");**$**list**-&gt;**put**("country","Paris");**$**list**-&gt;**put**("language","French");*

*$**flag** = $**list**-&gt;**exists**("age"); // It return true*

*if( $**flag** ){**echo "The field exists!!!";**}*

### cloneMe()

[](#cloneme)

It returns another FieldList with the same values of the element of the current list, these are not the same elements.

*$**exp** = **new** **FieldList**();*

*$**exp**-&gt;**put**("name","Alan");*

*$**exp**-&gt;**put**("lastname","Brooks");*

*$**exp**-&gt;**put**("email","");*

*$current = $**exp**-&gt;**cloneMe**();*

*echo "\\nClone list: " . $**exp**; // output -&gt; Clone list: {{"name":"Alan"},{"lastname":"Brooks"},{"email":""}}*

### copy()

[](#copy)

This method copy the values of the fields from another list that exists in the current list, the values that have a null value in the another list are not modified or assigned to the fields of the current list.

*$**list** = **new** **FieldList**();*

*$**list**-&gt;**put**("name","Alan");**$**list**-&gt;**put**("lastname","Brooks");**$**list**-&gt;**put**("email","");**$**list**-&gt;**put**("age",21);**$**list**-&gt;**put**("phone","3332225555");**$**list**-&gt;**put**("country","Paris");**$**list**-&gt;**put**("language","French");*

*$**anotherList** = **new** **FieldList**();*

*$**anotherList**-&gt;**put**("lastname","none");**$**anotherList**-&gt;**put**("email","none");**$**anotherList**-&gt;**put**("city","Arizona");*

*$**anotherList**-&gt;**copy**( $**list** );*

*echo "Current list: " . **$anotherList**; // Output-&gt; Current list: {{"lastname":"Brooks"},{"email":""},{"city":"Arizona"}}*

### copyNullToo()

[](#copynulltoo)

It copy the values of the fields that exists in the current list and in the another list, this include the null values.

*$**list** = **new** **FieldList**();*

*$**list**-&gt;**put**("name","Alan");**$**list**-&gt;**put**("lastname","Brooks");**$**list**-&gt;**put**("email","");**$**list**-&gt;**put**("age",21);**$**list**-&gt;**put**("phone","3332225555");**$**list**-&gt;**put**("country","Paris");**$**list**-&gt;**put**("language","French");*

*$**anotherList** = **new** **FieldList**();*

*$**anotherList**-&gt;**put**("lastname","none");**$**anotherList**-&gt;**put**("email","none");**$**anotherList**-&gt;**put**("city","Arizona");*

*$**anotherList**-&gt;**copyNullToo**( $**list** );*

*echo "Current list: " . $**anotherList**; // Output-&gt; Current list: {{"lastname":"Brooks"},{"email":""},{"city":null}}*

### copyAll()

[](#copyall)

It removes all attributes of the current list and copies all fields of the target list.

*$**list** = **new** **FieldList**();*

*$**list**-&gt;**put**("name","Alan");*

*$**list**-&gt;**put**("lastname","Brooks");*

*$**list**-&gt;**put**("email","");*

*$**copyList** = **new** **FieldList**();*

*$**copyList**-&gt;**copy**( $list );*

*echo "\\nCopy list: " . $**copyList**; // output -&gt; Copy list: {{"name":"Alan"},{"lastname":"Brooks"},{"email":""}}*

### compareTo()

[](#compareto)

It compares the fields of the current list with fields with the same name of the target list; other fields on the target list are discarded. If one field of the current list doesn’t exist in the target list or has a different value then the method returns false.

*$**list** = **new** **FieldList**();*

*$**list**-&gt;**put**("name","Alan");*

*$**list**-&gt;**put**("lastname","Brooks");*

*$**list**-&gt;**put**("email","");*

*$**list**-&gt;**put**("age",21);*

*$**list**-&gt;**put**("phone","3332225555");*

*$**anotherList** = new **FieldList**();*

*$**anotherList**-&gt;**put**("lastname","Brooks");*

*$**anotherList**-&gt;**put**("email","");*

*if( $**anotherList**-&gt;**compareTo**( $**list** ) ){ // expected value is true*

*echo "\\nThe fields exist and the values are the same.";*

*}else{*

*echo "\\nMaybe some fields not exists or the values are different.";*

*}*

### fieldsExistIn()

[](#fieldsexistin)

It verify the if the fields of the current list exist in the target list, the values and other fields are ignored in this process

*$**list** = **new** **FieldList**();*

*$**list**-&gt;**put**("name","Alan");*

*$**list**-&gt;**put**("lastname","Brooks");*

*$**list**-&gt;**put**("email","");*

*$**list**-&gt;**put**("age",21);*

*$**list**-&gt;**put**("phone","3332225555");*

*$**anotherList** = new **FieldList**();*

*$**anotherList**-&gt;**put**("lastname","Brooks");*

*$**anotherList**-&gt;**put**("email","");*

*if( $**anotherList**-&gt;**fieldsExistIn**( $**list** ) ){ // expected value is true*

*echo "\\nThe fields exists in the list.";*

*}else{*

*echo "\\nMaybe some fields not exists in the list.";*

*}*

### getIndex()

[](#getindex)

It returns the value from a specific position in the list.

*$**list** = **new** **FieldList**();*

*$**list**-&gt;**put**("name","Alan");*

*$**list**-&gt;**put**("lastname","Brooks");*

*$**list**-&gt;**put**("email","");*

*$**list**-&gt;**put**("age",21);*

*$**list**-&gt;**put**("phone","3332225555");*

*for( $i = 0; $i &lt; **$list-&gt;size()**; $i++ ){*

*echo "\\n..".$i.") ".**$list-&gt;getIndex($i)**; // get the value of a specific index.*

*}*

### getValueByIndex()

[](#getvaluebyindex)

It return a value of the list using the position of the field , if a filed doesn't exists in the position specified then return null.

*$**list** = **new** **FieldList**();*

*$**list**-&gt;**put**("name","Alan"); // position: 0**$**list**-&gt;**put**("lastname","Brooks"); // position: 1**$**list**-&gt;**put**("email",""); // position: 2**$**list**-&gt;**put**("age",21); // position: 3**$**list**-&gt;**put**("phone","3332225555"); // position: 4**$**list**-&gt;**put**("country","Paris"); // position: 5**$**list**-&gt;**put**("language","French"); // position: 6*

*$**phone** = $**list**-&gt;**getValueByIndex**( 4 );*

*echo "\\nPhone number: " . $**phone**; // Output: Phone number: 3332225555*

License
-------

[](#license)

This project is licensed under the [MIT License](LICENSE).

Last updated: Jun 1, 2024

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

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

717d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef2909fd70340f0fab06018ffbdc5c1b6a16996886ded8ce82e7619594684dd6?d=identicon)[S16M4](/maintainers/S16M4)

---

Top Contributors

[![arpablue](https://avatars.githubusercontent.com/u/69515175?v=4)](https://github.com/arpablue "arpablue (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/arpablue-fieldlist/health.svg)

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

###  Alternatives

[php-junior/laravel-video-chat

Laravel Video Chat using Socket.IO and WebRTC

82018.1k](/packages/php-junior-laravel-video-chat)[hiqdev/hipanel-core

HiPanel core package

3821.5k2](/packages/hiqdev-hipanel-core)[generoi/wp-gutenberg-button-popup

A boilerplate WordPress Gutenberg block

181.5k](/packages/generoi-wp-gutenberg-button-popup)

PHPackages © 2026

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