PHPackages                             israelalagbe/php-custom-types - 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. israelalagbe/php-custom-types

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

israelalagbe/php-custom-types
=============================

This package holds some custom PHP types such as Array and String. It provides functionalities similar to array and string in Javascript.

0.8(3mo ago)62841MITPHPPHP &gt;=8.1

Since Apr 5Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/israelalagbe/php-custom-types)[ Packagist](https://packagist.org/packages/israelalagbe/php-custom-types)[ RSS](/packages/israelalagbe-php-custom-types/feed)WikiDiscussions main Synced 3d ago

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

Custom PHP Types
================

[](#custom-php-types)

This package holds some custom PHP types such as Array and String. It provides functionalities similar to array and string in Javascript.

[![Standard PHP vs Custom Types](screenshot.svg)](screenshot.svg)

Installation
------------

[](#installation)

Require this package

```
composer require israelalagbe/php-custom-types
```

Array Types
-----------

[](#array-types)

### Basic Usage

[](#basic-usage)

You can use it the following way

```
use IsraelAlagbe\CustomTypes\_Array;

// Creating an array
$items = new _Array([1, 2, 3]); // or new _Array(1, 2, 3)

// Push items
$items->push(4);        // [1, 2, 3, 4]
$items->push(5, 6);     // [1, 2, 3, 4, 5, 6]

// Map through items
$doubled = $items->map(function($item) {
    return $item * 2;
});  // [2, 4, 6, 8, 10, 12]

echo $doubled; // Outputs: [2, 4, 6, 8, 10, 12]

// To get the original PHP array
print_r($items->toArray()); // [1, 2, 3, 4, 5, 6]
```

### Iterating with foreach

[](#iterating-with-foreach)

The `_Array` class implements `IteratorAggregate`, so you can iterate using a standard `foreach` loop:

```
use IsraelAlagbe\CustomTypes\_Array;

$fruits = new _Array(['apple', 'banana', 'cherry']);

// Standard foreach loop
foreach ($fruits as $fruit) {
    echo $fruit . '\n';
}
// Output:
// apple
// banana
// cherry

// Foreach with keys
foreach ($fruits as $index => $fruit) {
    echo "$index: $fruit" . '\n';
}
// Output:
// 0: apple
// 1: banana
// 2: cherry

// Using forEach method (callback style)
$fruits->forEach(function($fruit, $index) {
    echo "Item $index is $fruit" . '\n';
});
```

### Filtering and Searching

[](#filtering-and-searching)

```
use IsraelAlagbe\CustomTypes\_Array;

$numbers = new _Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

// Filter even numbers
$evens = $numbers->filter(function($n) {
    return $n % 2 === 0;
}); // [2, 4, 6, 8, 10]

// Check if value exists
$numbers->contains(5);     // true
$numbers->contains(100);   // false

// Find index of a value
$numbers->indexOf(3);      // 2
$numbers->indexOf(100);    // -1

// Check if key exists
$numbers->has(0);          // true
$numbers->has(100);        // false
```

### Stack Operations

[](#stack-operations)

```
use IsraelAlagbe\CustomTypes\_Array;

$stack = new _Array([1, 2, 3]);

// Push to the end
$stack->push(4);       // [1, 2, 3, 4]

// Pop from the end
$last = $stack->pop(); // Returns 4, array is now [1, 2, 3]

// Unshift (add to beginning)
$stack->unshift(0);    // [0, 1, 2, 3]

// Shift (remove from beginning)
$first = $stack->shift(); // Returns 0, array is now [1, 2, 3]
```

### Array Manipulation

[](#array-manipulation)

```
use IsraelAlagbe\CustomTypes\_Array;

$arr = new _Array(['a', 'b', 'c', 'd', 'e']);

// Join elements
$arr->join('-');        // "a-b-c-d-e"
$arr->join(', ');       // "a, b, c, d, e"

// Reverse array
$reversed = $arr->reverse(); // ['e', 'd', 'c', 'b', 'a']

// Slice array
$sliced = $arr->slice(1, 3); // ['b', 'c', 'd']

// Get keys and values
$arr->keys();           // [0, 1, 2, 3, 4]
$arr->values();         // ['a', 'b', 'c', 'd', 'e']

// Get length
$arr->length();         // 5
count($arr);            // 5 (Countable interface)

// Remove specific value
$arr->remove('c');      // ['a', 'b', 'd', 'e']

// Clear array
$arr->clear();          // []
```

### Array Access

[](#array-access)

```
use IsraelAlagbe\CustomTypes\_Array;

$arr = new _Array(['x', 'y', 'z']);

// Access by index
echo $arr[0];           // 'x'
echo $arr[2];           // 'z'

// Use item() for negative index support
echo $arr->item(-1);    // 'z' (last element)
echo $arr->item(-2);    // 'y' (second to last)

// Set by index
$arr[1] = 'Y';          // ['x', 'Y', 'z']
$arr[] = 'w';           // ['x', 'Y', 'z', 'w']

// Check if index exists
isset($arr[0]);         // true

// Unset index
unset($arr[0]);
```

### Conversion Methods

[](#conversion-methods)

```
use IsraelAlagbe\CustomTypes\_Array;

$arr = new _Array(['name' => 'John', 'age' => 30]);

// Convert to native PHP array
$native = $arr->toArray();  // ['name' => 'John', 'age' => 30]

// Convert to JSON
$json = $arr->toJSON();     // '{"name":"John","age":30}'

// String representation
echo $arr;                  // [John, 30]
```

---

String Types
------------

[](#string-types)

### Basic Usage

[](#basic-usage-1)

```
use IsraelAlagbe\CustomTypes\_String;

// Creating a string
$str = new _String('Hello World');

echo $str;              // Hello World
echo $str->count();     // 11
```

### Searching and Checking

[](#searching-and-checking)

```
use IsraelAlagbe\CustomTypes\_String;

$str = new _String('The quick brown fox jumps over the lazy dog');

// Find index of substring
$str->indexOf('quick');     // 4
$str->indexOf('cat');       // -1 (not found)

// Check if contains substring
$str->contains('fox');      // true
$str->contains('cat');      // false
```

### String Manipulation

[](#string-manipulation)

```
use IsraelAlagbe\CustomTypes\_String;

$str = new _String('  Hello World  ');

// Trim whitespace
$trimmed = $str->trim();    // 'Hello World'

// Reverse string
$str2 = new _String('Hello');
$reversed = $str2->reverse(); // 'olleH'

// Clear string
$str2->clear();             // ''
```

### Splitting Strings

[](#splitting-strings)

```
use IsraelAlagbe\CustomTypes\_String;

$str = new _String('apple,banana,cherry');

// Split by delimiter
$fruits = $str->split(',');  // _Array(['apple', 'banana', 'cherry'])

// Split into characters
$str2 = new _String('Hello');
$chars = $str2->split('');   // _Array(['H', 'e', 'l', 'l', 'o'])

// Split with no delimiter (returns single-element array)
$single = $str->split();     // _Array(['apple,banana,cherry'])
```

### Template Substitution

[](#template-substitution)

```
use IsraelAlagbe\CustomTypes\_String;

$template = new _String('Hello, {name}! You are {age} years old.');

$result = $template->substitute([
    'name' => 'John',
    'age' => 25
]); // 'Hello, John! You are 25 years old.'

// Missing placeholders are removed
$template2 = new _String('{greeting}, {name}!');
$result2 = $template2->substitute(['name' => 'Alice']); // ', Alice!'
```

### Case Conversion

[](#case-conversion)

```
use IsraelAlagbe\CustomTypes\_String;

// Convert to camelCase (from dash-case)
$str = new _String('my-variable-name');
$camel = $str->camelCase(); // 'myVariableName'
```

### Array Access and Iteration

[](#array-access-and-iteration)

```
use IsraelAlagbe\CustomTypes\_String;

$str = new _String('Hello');

// Access individual characters
echo $str[0];              // 'H'
echo $str[4];              // 'o'

// Iterate through characters
foreach ($str as $index => $char) {
    echo "$index: $char" . '\n';
}
// Output:
// 0: H
// 1: e
// 2: l
// 3: l
// 4: o

// Count characters
echo count($str);          // 5
```

### Conversion Methods

[](#conversion-methods-1)

```
use IsraelAlagbe\CustomTypes\_String;

$str = new _String('Hello');

// Convert to array of characters
$chars = $str->toArray();   // ['H', 'e', 'l', 'l', 'o']

// Convert to JSON
$json = $str->toJSON();     // '"Hello"'
```

### Chaining Methods

[](#chaining-methods)

```
use IsraelAlagbe\CustomTypes\_String;

// Methods that return new _String instances can be chained
$str = new _String('  hello-world  ');

$result = $str->trim()->camelCase(); // 'helloWorld'
```

---

Testing
-------

[](#testing)

If you forked this package, you can test using the command below.

```
composer test
```

License
-------

[](#license)

MIT

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance79

Regular maintenance activity

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

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

Every ~219 days

Recently: every ~425 days

Total

9

Last Release

113d ago

PHP version history (2 changes)0.5.0PHP &gt;=5.6

0.8PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/22811493?v=4)[Israel Alagbe](/maintainers/israelalagbe)[@israelalagbe](https://github.com/israelalagbe)

---

Top Contributors

[![israelalagbe](https://avatars.githubusercontent.com/u/22811493?v=4)](https://github.com/israelalagbe "israelalagbe (37 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/israelalagbe-php-custom-types/health.svg)

```
[![Health](https://phpackages.com/badges/israelalagbe-php-custom-types/health.svg)](https://phpackages.com/packages/israelalagbe-php-custom-types)
```

###  Alternatives

[wapmorgan/morphos

A morphological solution for Russian and English language written completely in PHP. Provides classes to inflect personal names, geographical names, decline and pluralize nouns, generate cardinal and ordinal numerals, spell out money amounts and time.

8351.3M7](/packages/wapmorgan-morphos)[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.4k423.9k30](/packages/mcp-sdk)[hackzilla/password-generator

Password Generator Library

3035.2M15](/packages/hackzilla-password-generator)[alibaba/nacos

阿里巴巴nacos配置中心php客户端

19340.8k1](/packages/alibaba-nacos)[bvdputte/kirby-fingerprint

Cache-busting utility to fingerprint assets (JS/CSS) in Kirby 3

1610.0k](/packages/bvdputte-kirby-fingerprint)

PHPackages © 2026

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