Skip to content

Instantly share code, notes, and snippets.

@vmanyushin
Created October 5, 2018 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmanyushin/39d6ac7d86e6b9eed25067143764e969 to your computer and use it in GitHub Desktop.
Save vmanyushin/39d6ac7d86e6b9eed25067143764e969 to your computer and use it in GitHub Desktop.
<?php
class Row {
public function __construct(array $attributes = [])
{
foreach ($attributes as $name => $value) {
$this->{$name} = $value;
}
}
}
class User {
public function __construct(array $rows = [])
{
$this->obj = $rows[0];
$this->obj->loc_work = array_map(function($a) { return $a->loc_work;}, $rows);
$this->obj->profession = array_map(function($a) { return $a->profession;}, $rows);
$this->obj->com_name = array_map(function($a) { return $a->com_name;}, $rows);
$this->obj->com_inds = array_map(function($a) { return $a->com_inds;}, $rows);
}
}
$rows = [
new Row([
'id' => '1',
'first_name' => 'Хабиб',
'last_name' => 'Макгрэгович',
'email' => 'dvoeglazov.ilya@yandex.ru',
'location' => 'United States',
'picture' => 'https://media.licdn.com/dms/image/C4D03AQF7xeYVfWV...',
'profile_url' => 'www.linkedin.com/in/%D1%85%D0%B0%D0%B1%D0%B8%D0%B1...',
'industry' => 'Information Technology and Services',
'created' => '2018-10-04 23:13:00',
'loc_work' => 'Saint Petersburg, Russian Federation',
'profession' => 'Frontend Engineer',
'com_name' => 'Paladin Engineering',
'com_inds' => 'Информационные технологии и услуги',
]),
new Row([
'id' => '1',
'first_name' => 'Хабиб',
'last_name' => 'Макгрэгович',
'email' => 'dvoeglazov.ilya@yandex.ru',
'location' => 'United States',
'picture' => 'https://media.licdn.com/dms/image/C4D03AQF7xeYVfWV...',
'profile_url' => 'www.linkedin.com/in/%D1%85%D0%B0%D0%B1%D0%B8%D0%B1...',
'industry' => 'Information Technology and Services',
'created' => '2018-10-04 23:13:00',
'loc_work' => '',
'profession' => 'Капитан команды',
'com_name' => 'Яндекс Терра',
'com_inds' => 'Нефтяная и энергетическая промышленность',
])
];
$user = new User($rows);
echo print_r($user->obj);
?>
Row Object
(
[id] => 1
[first_name] => Хабиб
[last_name] => Макгрэгович
[email] => dvoeglazov.ilya@yandex.ru
[location] => United States
[picture] => https://media.licdn.com/dms/image/C4D03AQF7xeYVfWV...
[profile_url] => www.linkedin.com/in/%D1%85%D0%B0%D0%B1%D0%B8%D0%B1...
[industry] => Information Technology and Services
[created] => 2018-10-04 23:13:00
[loc_work] => Array
(
[0] => Saint Petersburg, Russian Federation
[1] =>
)
[profession] => Array
(
[0] => Frontend Engineer
[1] => Капитан команды
)
[com_name] => Array
(
[0] => Paladin Engineering
[1] => Яндекс Терра
)
[com_inds] => Array
(
[0] => Информационные технологии и услуги
[1] => Нефтяная и энергетическая промышленность
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment