PHP code example of solidworx / util
1. Go to this page and download the library: Download solidworx/util 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/ */
solidworx / util example snippets
$input = [
['test' => 'one'],
['test' => 'two'],
['test' => 'three'],
];
$columns = ArrayUtil::column($input, 'test');
/* $columns = array (
0 => 'one',
1 => 'two',
2 => 'three',
);*/
class Foo {
public $test;
}
$foo1 = new Foo;
$foo1->test = 'one';
$foo2 = new Foo;
$foo2->test = 'two';
$foo3 = new Foo;
$foo3->test = 'three';
$input = [
$foo1,
$foo2,
$foo3,
];
$columns = ArrayUtil::column($input, 'test');
/* $columns = array (
0 => 'one',
1 => 'two',
2 => 'three',
);*/
class Foo {
private $value;
public function __construct($value)
{
$this->value = $value;
}
public function test()
{
return $this->>value;
}
}
$input = [
new Foo('one'),
new Foo('two'),
new Foo('three'),
];
$columns = ArrayUtil::column($input, 'test');
/* $columns = array (
0 => 'one',
1 => 'two',
2 => 'three',
);*/
class Foo {
private $value;
public function __construct($value)
{
$this->value = $value;
}
public function getTest()
{
return $this->value;
}
}
$input = [
new Foo('one'),
new Foo('two'),
new Foo('three'),
];
$columns = ArrayUtil::column($input, 'test');
/* $columns = array (
0 => 'one',
1 => 'two',
2 => 'three',
);*/
$users = $userRepository->findAll();
$emails = ArrayUtil::column($users, 'email');
$users = $userRepository->findAll();
$emails = ArrayUtil::column($users, 'email', false); // Will keep empty values in the result