Download the PHP package morrelinko/array-take without Composer

On this page you can find all versions of the php package morrelinko/array-take. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package array-take

array_take()

When dealing with arrays, retrieving elements from them can be cumbersome. Some create an extra array that stores the elements that are expected and do lots of isset checking on the original array.

For example, if you wanted to retrieve some values from forms, you may do something like this: (This is just an example)

<?php

if (isset($createData["username"])) {
    $createData["username"] = $_POST["username"];
}

if (isset($createData["first_name"])) {
    $createData["first_name"] = $_POST["fname"];
}

if (isset($createData["password"])) {
    $createData["password"] = password_hash($_POST["username"], PASSWORD_DEFAULT);
}

$someService->createUser($createData);

Imagine if you were to process a very long form!!

Enough already! array_take provides a better way:

<?php

$createData = Morrelinko\array_take($_POST, [
    "username",
    "first_name" => "fname",
    "password" => function($value) {
        return password_hash($value, PASSWORD_DEFAULT):
    }
]);

$someService->createUser($createData);

Usage

Retrieve values from a one-dimensional array Note: if a specified key is not available in the array, it is skipped and not included in the new array.

<?php

$user = [
    "name" => "Laju Morrison",
    "hobby" => "None",
    "wedontneedthis" => "somevalue"
];

$correctedUser = Morrelinko\array_take($user, ["name", "hobby"]);

/**
 * Output:
 *
 *  [
 *      "name" => "Laju Morrison",
 *      "hobby" => "None",
 *  ]
 */

Renaming keys on the new array

<?php

$user = [
    "name" => "Laju Morrison",
    "birthday" => "1000/ask/google",
    "wedontneedthis" => "somevalue"
];

$user = Morrelinko\array_take($user, ["name" => "user_name", "birthday"]);

/**
 * Output:
 *
 *  [
 *      "user_name" => "Laju Morrison",
 *      "birthday" => "1000/ask/google",
 *  ]
 */

Modify value via Anonymous function

<?php

$user = [
        "name" => "Laju Morrison",
        "password" => "123456"
    ];

$user = Morrelinko\array_take($user, [
    "name",
    "password" => function($value) {
        return password_hash($value, PASSWORD_BCRYPT):
    }
]);

/**
 * Output:
 *
 *  [
 *      "name" => "Laju Morrison",
 *      "password" => "$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K",
 *  ]
 */

If a two dimensional array is passed to it, the filter is applied to each item in the list

<?php

$users = [
    ["name" => "Laju Morrison", "status" => "Dreaming..."],
    ["name" => "John Doe", "status" => ""],
    ["name" => "Mary Alice", "status" => ""]
];

$users = Morrelinko\array_take($users, ["name"]);

    /**
     * Output:
     *
     *  [
     *      ["name" => "Laju Morrison"],
     *      ["name" => "John Doe"],
     *      ["name" => "Mary Alice"]
     *  ]
     */

Enjoy Coding!!

Supported by http://contactlyapp.com


All versions of array-take with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package morrelinko/array-take contains the following files

Loading the files please wait ....