Download the PHP package jsarray/jsarray without Composer
On this page you can find all versions of the php package jsarray/jsarray. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jsarray/jsarray
More information about jsarray/jsarray
Files in jsarray/jsarray
Package jsarray
Short Description JavaScript-accurate Array wrapper for PHP with immutable operations
License MIT
Homepage https://github.com/omer73364/jsarray
Informations about the package jsarray
JsArray - JavaScript Arrays in PHP
Write JavaScript Array code in PHP. Familiar, powerful, and intuitive API for working with arrays.
If you know JavaScript arrays, you already know JsArray.
What is JsArray?
JsArray brings the beloved JavaScript Array methods to PHP with:
- ✅ Familiar API - Same methods, same behavior as JavaScript
- ✅ Full Type Safety - PHP 8+ with complete type hints
- ✅ Flexible - Choose immutable (safe) or mutable (fast) mode
- ✅ Pure PHP - Zero dependencies, lightweight
- ✅ Native PHP Interoperability - Behaves like a first-class PHP collection
Installation
Requirements: PHP 8.0+
Quick Start
The Basics
Working with Objects
Flexible Callback Signatures
Use only the parameters you need:
JsArray automatically detects which parameters your callback uses. No configuration needed!
Native PHP Interoperability
JsArray behaves like a first‑class PHP collection and integrates naturally with core language features.
Iteration (Iterator)
Use JsArray directly in foreach loops:
No conversion needed.
ArrayAccess
Use JsArray as an array:
Counting (Countable)
Use PHP’s native count() function:
Equivalent to:
JSON Serialization (JsonSerializable)
Serialize JsArray cleanly using json_encode():
Output:
Create a JsArray from a JSON string:
This makes JsArray ideal for APIs, responses, and data transport without extra mapping.
Core Features
Transformation
Search
Access
Manipulation
Other
Two Modes: Immutable & Mutable
Immutable Mode (Default)
Creates a new array for each operation. Original is never changed.
Use immutable when:
- Processing user input
- Data safety matters
- Building complex logic
- Working with small to medium arrays (< 10,000 items)
Mutable Mode (Fast)
Modifies the array in-place. Much faster for large datasets.
Use mutable when:
- Processing large datasets (> 50,000 items)
- Performance is critical
- Building or accumulating data
- Bulk operations (imports, migrations)
Converting Between Modes
Start with immutable, convert if needed
Create mutable copy without affecting original
Convert back to immutable
Check the mode:
Testing
Run tests:
Tests include:
- 190+ test cases
- All methods covered
- Edge cases tested
- Immutable/mutable modes tested
Contributing
We welcome contributions!
- Fork the repository
- Create a feature branch
- Write tests for your changes
- Ensure tests pass
- Submit a pull request
Documentation Files
- API.md - Complete API reference
- PATTERNS.md - Common patterns and recipes
- EXAMPLES.md - Real-world usage examples
- PERFORMANCE.md - Performance analysis and tips
- MUTABILITY.md - Deep dive into mutable/immutable modes
License
MIT License - See LICENSE for details.
Support
Changelog
v2.1.0
✨ Enhanced native PHP interoperability:
- Iteration (Iterator): Seamless
foreachloop support - ArrayAccess: Access elements using array syntax (e.g.,
$array[0]) - Counting (Countable): Native
count()function integration - JSON Serialization (JsonSerializable): Direct
json_encode()support - JSON Deserialization: Create JsArray from JSON strings with
fromJson()
v2.0.0
- ✨ Added mutable mode for performance
- ✨ 5 new methods (shift, unshift, indexOf, lastIndexOf, reverse)
- ✨ Flexible callback signatures (use only params you need!)
- ✨ Depth parameter for flat()
- 🐛 Fixed filter re-indexing for numeric arrays
- 📚 Comprehensive documentation files
v1.0.0
- Initial release