Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.