Arrays::renameKey chyba nebo bug?

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
t0x1c
Člen | 151
+
0
-

Zdravím nevím jestli jsem blbý já nebo jsem narazil na bug v nette. Mám pole 0–9 čili 10 položek. Každou chci přejmenovat na id pomoci funkce Arrays::renameKey. Mám kod:

$delka = 10;
for ($i = 0; $i <= $delka-1; $i++) {
            Arrays::renameKey($test, $i, $test[$i]['id']);
        }

Na konci je přejmenovano jen 9 prvku a 7 prvek prostě chybí.

Jan Tvrdík
Nette guru | 2595
+
0
-

@t0x1c: Kompletní kód by nebyl? To cos tady dal vypadá konceptuálně špatně.

Jan Tvrdík
Nette guru | 2595
+
0
-

Lépe něco jako:

foreach ($test as $val) {
	$test2[$val['id']] = $val;
}
t0x1c
Člen | 151
+
0
-

celý kod
prvni je to stdClass který převadím na array.

        function objectToArray($d) {
            if (is_object($d)) {
                // Gets the properties of the given object
                // with get_object_vars function
                $d = get_object_vars($d);
            }

            if (is_array($d)) {
                /*
                 * Return array converted to object
                 * Using __FUNCTION__ (Magic constant)
                 * for recursive call
                 */
                return array_map(__FUNCTION__, $d);
            } else {
                // Return array
                return $d;
            }
        }

        $this->template->servery = $this->servery->vypsatServery($this->getUser()->getIdentity()->id);
        $test = objectToArray($this->gamecp->gamecpAPI('service_list'));
        $delka = sizeof($test);
        for ($i = 0; $i <= $delka - 1; $i++) {
            Arrays::renameKey($test, $i, $test[$i]['id']);
        }
        $this->template->test = $test;
t0x1c
Člen | 151
+
0
-

Ok díky Honzo tak to co jsi napsal funguje :) Dík