public function join($method, $fields, $second, $match)
    {
        $left = $this->load();
        $right = $second->load();
        $result = [];
        $values = [];
        if ($method === 'inner') {
            foreach ($left as $l) {
                foreach ($right as $r) {
                    if ($l[array_keys($match)[0]] === $r[array_values($match)[0]]) {
                        $result[] = array_merge($l, $r);
                    }
                }
            }
        } elseif ($method === 'left') {
            foreach ($left as $l) {
                foreach ($right as $r) {
                    if ($l[array_keys($match)[0]] === $r[array_values($match)[0]]) {
                        $values = array_merge($l, $r);
                        break;
                    } else {
                        $values = $l;
                    }
                }
                $result[] = $values;
                $values = [];
            }
        } elseif ($method === 'right') {
            foreach ($left as $l) {
                foreach ($right as $r) {
                    if ($l[array_keys($match)[0]] === $r[array_values($match)[0]]) {
                        $values = array_merge($l, $r);
                        break;
                    } else {
                        $values = $r;
                    }
                }
                $result[] = $values;
                $values = [];
            }
        } elseif ($method === 'full') {
            $result = array_map(
                'unserialize', array_unique(
                    array_map(
                        'serialize', array_merge(
                            $this->join('left', $fields, $second, $match),
                            $this->join('right', $fields, $second, $match)
                        )
                    )
                )
            );
        }
        return self::arraySelect($fields, $result);
    }
public function join($method, $fields, $second, $match)
    {
        $left = $this->load();
        $right = $second->load();
        $result = [];
        $values = [];
        if ($method === 'inner') {
            foreach ($left as $l) {
                foreach ($right as $r) {
                    if ($l[array_keys($match)[0]] === $r[array_values($match)[0]]) {
                        $result[] = array_merge($l, $r);
                    }
                }
            }
        } elseif ($method === 'left') {
            foreach ($left as $l) {
                foreach ($right as $r) {
                    if ($l[array_keys($match)[0]] === $r[array_values($match)[0]]) {
                        $values = array_merge($l, $r);
                        break;
                    } else {
                        $values = $l;
                    }
                }
                $result[] = $values;
                $values = [];
            }
        } elseif ($method === 'right') {
            foreach ($left as $l) {
                foreach ($right as $r) {
                    if ($l[array_keys($match)[0]] === $r[array_values($match)[0]]) {
                        $values = array_merge($l, $r);
                        break;
                    } else {
                        $values = $r;
                    }
                }
                $result[] = $values;
                $values = [];
            }
        } elseif ($method === 'full') {
            $result = array_map(
                'unserialize', array_unique(
                    array_map(
                        'serialize', array_merge(
                            $this->join('left', $fields, $second, $match),
                            $this->join('right', $fields, $second, $match)
                        )
                    )
                )
            );
        }
        return self::arraySelect($fields, $result);
    }
public function join ( $ method , $ fields , $ second , $ match ) { $ left = $ this -> load ( ) ; $ right = $ second -> load ( ) ; $ result = [ ] ; $ values = [ ] ; if ( $ method === 'inner' ) { foreach ( $ left as $ l ) { foreach ( $ right as $ r ) { if ( $ l [ array_keys ( $ match ) [ 0 ] ] === $ r [ array_values ( $ match ) [ 0 ] ] ) { $ result [ ] = array_merge ( $ l , $ r ) ; } } } } elseif ( $ method === 'left' ) { foreach ( $ left as $ l ) { foreach ( $ right as $ r ) { if ( $ l [ array_keys ( $ match ) [ 0 ] ] === $ r [ array_values ( $ match ) [ 0 ] ] ) { $ values = array_merge ( $ l , $ r ) ; break ; } else { $ values = $ l ; } } $ result [ ] = $ values ; $ values = [ ] ; } } elseif ( $ method === 'right' ) { foreach ( $ left as $ l ) { foreach ( $ right as $ r ) { if ( $ l [ array_keys ( $ match ) [ 0 ] ] === $ r [ array_values ( $ match ) [ 0 ] ] ) { $ values = array_merge ( $ l , $ r ) ; break ; } else { $ values = $ r ; } } $ result [ ] = $ values ; $ values = [ ] ; } } elseif ( $ method === 'full' ) { $ result = array_map ( 'unserialize' , array_unique ( array_map ( 'serialize' , array_merge ( $ this -> join ( 'left' , $ fields , $ second , $ match ) , $ this -> join ( 'right' , $ fields , $ second , $ match ) ) ) ) ) ; } return self :: arraySelect ( $ fields , $ result ) ; }
Matches and merges fields between databases.

@param string $method    the method to join (inner, left, right, full)
@param array $fields     the fields to select
@param Database $second  the second database to use
@param array $match      a key-value pair consisting of the left field name against the right field name
@return array            the joined data set
Matches and merges fields between databases .