PHP code example of dcelasun / extract_property

1. Go to this page and download the library: Download dcelasun/extract_property library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dcelasun / extract_property example snippets


array extract_property( array $objects, mixed $key [, mixed $index] )
 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');