PHPackages                             es02/knapper - 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. es02/knapper

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

es02/knapper
============

A simple knapsack solver aimed at shipping and logistics.

14[1 PRs](https://github.com/es02/knapper/pulls)PHP

Since Oct 15Pushed 6y ago1 watchersCompare

[ Source](https://github.com/es02/knapper)[ Packagist](https://packagist.org/packages/es02/knapper)[ RSS](/packages/es02-knapper/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Knapper
=======

[](#knapper)

Simple, dependency-free knapsack solver

Master: [![Build Status: Master](https://camo.githubusercontent.com/314460677d6b17868a673b8c943e84fd3d5def08c2ee969b26a3fc02a604bda0/68747470733a2f2f7472617669732d63692e636f6d2f657330322f6b6e61707065722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/es02/knapper)

Dev: [![Build Status: Dev](https://camo.githubusercontent.com/37f2634a2a1186c0d95b65476b9bcacf8d31d60a1373c72df451b3229a9c5f35/68747470733a2f2f7472617669732d63692e636f6d2f657330322f6b6e61707065722e7376673f6272616e63683d646576)](https://travis-ci.com/es02/knapper)

Getting Started
---------------

[](#getting-started)

These instructions will get you a copy of the project installed in your composer dependencies.

### Prerequisites

[](#prerequisites)

PHP 7

### Installing

[](#installing)

Adding knapper to your project is as simple as adding it to your composer.json

```
composer require es02/knapper

```

### Usage

[](#usage)

```
$knapper = new Knapper($items, $boxes);
$results = $knapper->pack();

```

To use Knappper you will need an array of objects to be packed and an array of boxes to pack them into. Optionally you can supply the following fields:

- maxCubic (Default: null) - Set an upper limit on cubic weight for boxes
- maxWeight (Default: null) - set an upper limit on physical weight for boxes
- weightType (Options: 'g', 'kg', 'oz', 'lb') (Default: 'g') - Choose metric or imperial measurements for that weight

Some carriers require boxes in a shipment to remain below certain cubic/gross weight limits. These options allow you to achieve this with minimal effort.

```
$knapper = new Knapper($items, $boxes, 15, 15 , 'kg');
$results = $knapper->pack();

```

Both arrays require the following fields:

- length
- width
- height
- weight

```
$items[] = array('length' => 10, 'width' => 50, 'height' => 200, 'weight' => 2);
$boxes[] = array('length' => 20, 'width' => 60, 'height' => 250, 'weight' => 2.5);

```

In addition both support the following optional fields:

- name (Default: null) - Allows you to set a human readable name for your item/box
- lengthType (Options: 'cm', 'm', 'in', 'ft') (Default: 'cm') - Sets measurement type
- weightType (Options: 'g', 'kg', 'oz', 'lb') (Default: 'g') - Sets measurement type

Boxes can have the following optional fields

- quantity (Default: 0) - Sets whether or not a box size has a limited supply, leave at 0 for unlimited

Items can have the following optional fields

- thisWayUp (Default: false) - Sets whether or not the item can be placed on it's side

*Where not manually set, optional fields will use their default values*

```
$items[] = array(
    'name' => "Sculpture"
    'length' => 10,
    'width' => 50,
    'height' => 200,
    'weight' => 2,
    'lengthType' => 'in',
    'weightType' => 'lb',
    'thisWayUp' => false
);
$boxes[] = array(
    'name' => "Large Packing Box",
    'length' => 20,
    'width' => 60,
    'height' => 250,
    'weight' => 2.5,
    'lengthType' => 'in',
    'weightType' => 'lb',
    'quantity' => 20
);

```

Contributing
------------

[](#contributing)

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning
----------

[](#versioning)

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/es02/knapper/tags).

Authors
-------

[](#authors)

- **Aimi Hobson** - *Initial work* - [ArachnidsGrip](https://github.com/es02)

License
-------

[](#license)

This project is licensed under the GNU GPL - see the [LICENSE.md](LICENSE.md) file for details

Acknowledgments
---------------

[](#acknowledgments)

- ReadMe template from [PurpleBooth](https://gist.github.com/PurpleBooth/109311bb0361f32d87a2)
- Changelog Template from [KeepAChangelog](https://keepachangelog.com/en/1.0.0/)
- Contributing template from [PurpleBooth](https://gist.github.com/PurpleBooth/b24679402957c63ec426)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/92ed9378ac3a89370c8265f7194ae30a5ce4e28c93b319c49282a881e5e9eef7?d=identicon)[es02](/maintainers/es02)

---

Top Contributors

[![es02](https://avatars.githubusercontent.com/u/1310970?v=4)](https://github.com/es02 "es02 (36 commits)")

### Embed Badge

![Health badge](/badges/es02-knapper/health.svg)

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

PHPackages © 2026

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