Jak połączyć wartości tablicy wielowymiarowej w jedną duwymiarową?

0

Mam jedną tablicę indeksowaną numerycznie, w której jest 10 innych tablic. Czy istnieje jakiś prosty sposób, żeby zrobić z tego tablicę dwuwymiarową (zmergować w górę tak jakby) ? Coś na zasadzie

$array += $array_just_fetched

. W tym jest akurat taki problem, że mi zastępuje wartości dublujących się indeksów, a array merge z pustą tablicą (podczas pierwszej iteracji w pętli) zwraca nieciekawe wyniki, bo tylko pierwszą tablicę, nie bardzo wiem dlaczego :)

Ogólnie założenie jest takie, że w przy każdej itercji pętli chcę dodawać do tablicy X wartości tablicy Y(indeksowanej numerycznie). Tyle, że chciałbym to zrobić jakiś hurtowo, a nie robić kolejną pętlę i dodawać maualnie po jednej)

1

Parząc w manuala array_merge wnioskuję, że użycie tej funkcji powinno wystarczyć

Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.

If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended.

Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array.

Może zamieść kod który tobie nie zadziałał.

0
// var_dump($userModel->getCoordinatorUsers(true)); są dwie iteracje
 
array (size=1)
  0 => string '105' (length=3)
array (size=20)
  0 => string '97' (length=2)
  1 => string '1054' (length=4)
  2 => string '543' (length=3)
  3 => string '544' (length=3)
  4 => string '1131' (length=4)
  5 => string '1132' (length=4)
  6 => string '1052' (length=4)
  7 => string '987' (length=3)
  8 => string '1053' (length=4)
  9 => string '1049' (length=4)
  10 => string '984' (length=3)
  11 => string '1048' (length=4)
  12 => string '1047' (length=4)
  13 => string '1050' (length=4)
  14 => string '1046' (length=4)
  15 => string '545' (length=3)
  16 => string '986' (length=3)
  17 => string '1051' (length=4)
  18 => string '985' (length=3)
  19 => string '542' (length=3)
        if(!empty($this->_search['coordinator_id'])){
            $coordinatorIds = $this->_search['coordinator_id'];
            $users = array();
            foreach ($coordinatorIds as $id) {
                $userModel = new Core_Model_User($id);
                if(!empty($users))
                    array_merge($users, $userModel->getCoordinatorUsers(true));
                else
                    $users = $userModel->getCoordinatorUsers(true);
                var_dump($userModel->getCoordinatorUsers(true));
            }
            var_dump($users);die; // zwraca samo 105
            $select->where("q.created_by IN (?)", $users);
        }
<facepalm> Nie przypisywałem tego co zwraca array_merge... Tak to jest jak się rzadko używa tych funkcji. Myślałem, że tak jak array_push nadpisuje to oryginalną tablicę.

1 użytkowników online, w tym zalogowanych: 0, gości: 1