Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Arrayy Laravel Package

voku/arrayy

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation Add via Composer:

    composer require voku/arrayy
    

    No Laravel-specific setup is needed—just autoload the package.

  2. Basic Usage Import the core class:

    use voku\arrayy\Arrayy;
    

    Initialize with an array:

    $array = Arrayy::from([1, 2, 3, 'a', 'b']);
    
  3. First Use Case: Filtering Remove empty values:

    $filtered = $array->filterEmpty();
    // Result: [1, 2, 3, 'a', 'b']
    

Implementation Patterns

Common Workflows

  1. Data Transformation Use map() for value transformations:

    $doubled = $array->map(fn($val) => $val * 2);
    // Result: [2, 4, 6, 'aa', 'bb']
    
  2. Nested Array Handling Flatten multi-dimensional arrays:

    $flat = Arrayy::from([1, [2, 3]])->flatten();
    // Result: [1, 2, 3]
    

    Or extract values from nested keys:

    $users = Arrayy::from([['name' => 'Alice'], ['name' => 'Bob']])->pluck('name');
    // Result: ['Alice', 'Bob']
    
  3. Conditional Logic Filter with custom callbacks:

    $evens = $array->filter(fn($val) => $val % 2 === 0);
    // Result: [2]
    
  4. Laravel Integration Use with Eloquent collections:

    $collection = User::all()->toArray();
    $processed = Arrayy::from($collection)->filterEmpty();
    
  5. Batch Processing Chunk arrays for large datasets:

    $chunks = $array->chunk(2);
    // Result: [[1, 2], [3, 'a'], ['b']]
    

Gotchas and Tips

Pitfalls

  1. Immutable Operations Methods like map() return new arrays—they don’t modify the original. Chain methods carefully:

    // ❌ Overwrites $array
    $array->map(...)->filter(...);
    // ✅ Safe
    $result = $array->map(...)->filter(...);
    
  2. Key Preservation Some methods (e.g., filter()) may reindex arrays. Use filter() with true to preserve keys:

    $array->filter(fn($val) => $val > 1, true);
    
  3. Type Sensitivity arrayy treats null, false, 0, and '' as "empty" in filterEmpty(). Explicitly handle edge cases if needed.

  4. Performance Avoid deep recursion on large arrays (e.g., flatten()). For nested structures, consider iterative approaches.

Debugging Tips

  • Inspect Intermediate States Use Arrayy::from($array)->toArray() to debug transformations.
  • Leverage Laravel’s dd() Combine with Laravel’s helpers:
    dd(Arrayy::from($data)->pluck('key')->toArray());
    

Extension Points

  1. Custom Methods Extend Arrayy via traits or subclasses:

    use voku\arrayy\Arrayy as BaseArrayy;
    
    class CustomArrayy extends BaseArrayy {
        public function customMethod() { ... }
    }
    
  2. Integration with Laravel Collectors Convert to/from Laravel collections:

    $laravelCollection = collect(Arrayy::from($array)->toArray());
    
  3. Configuration No package-wide config exists, but you can wrap Arrayy in a service provider for global defaults (e.g., strict typing).

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle