承接 dcelasun/extract_property 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dcelasun/extract_property

Composer 安装命令:

composer require dcelasun/extract_property

包简介

Extracts a given property from an array of objects

README 文档

README

Build Status

This simple library provides an easy way to extract a given property from an array of objects.

Usage

array extract_property( array $objects, mixed $key [, mixed $index] )

Given an array of objects, extract_property() returns the values from a single property of each object, identified by $key. Optionally, you may provide an $index to index the values in the returned array by the values from the $index property of each object in the input array.

For example, using the following $users array, we tell extract_property() to return an array of just the names, indexed by their record IDs.

<?php
$users = array();

$a = new stdClass;
$b = new stdClass;
$c = new stdClass;

$a->id = 1;
$a->name = 'John';
$a->surname = 'Doe';

$users[] = $a;

$b->id = 2;
$b->name = 'Jane';
$b->surname = 'Doe';

$users[] = $b;

$c->id = 3;
$c->name = 'Foo';
$c->surname = 'Bar';

$users[] = $c;

$names = extract_property($users, 'name', 'id');

If we call print_r() on $names, you'll see a resulting array that looks a bit like this:

Array
(
    [1] => John
    [2] => Jane
    [3] => Foo
)

You could of course omit the $index so the resulting array looks like this:

Array
(
    [0] => John
    [1] => Jane
    [2] => Foo
)

Installation

The easiest way to install this library is to use Composer and add the following to your project's composer.json file:

{
    "require": {
        "dcelasun/extract_property": "1.*"
    }
}

Then, when you run composer install, everything will fall magically into place, and the extract_property() function will be available to your project, as long as you are including Composer's autoloader.

However, you do not need Composer to use this library.

This library has no dependencies and should work on older versions of PHP. Download the code and include src/extract_property.php in your project, and everything should work fine.

统计信息

  • 总下载量: 25
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-07-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固