Skip to content

Instantly share code, notes, and snippets.

@longkey1
Created April 16, 2016 07:12
Show Gist options
  • Save longkey1/ce90aa78ea679d17cbefcee183e9f92f to your computer and use it in GitHub Desktop.
Save longkey1/ce90aa78ea679d17cbefcee183e9f92f to your computer and use it in GitHub Desktop.
nagoyaphp-160416-sample
<?php
$input = '1->4';
$expected = 'mo';
// parse
list($one, $two) = explode('->', $input);
$people = [
1 => ['parent' => null, 'children' => [2,3,4]],
2 => ['parent' => 1, 'children' => []],
3 => ['parent' => 1, 'children' => []],
4 => ['parent' => 1, 'children' => []],
];
// search
$onePerson = $people[$one];
$twoPerson = $people[$two];
// mo
if ($onePerson['parent'] == $two) {
echo 'mo';
}
// da
if (in_array($two, $onePerson['children'])) {
echo 'da';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment