Potrzebuje przejsc tablice rekursywnie i pobrac wartosci na podstawie podanych kluczy.
Przykładowa tablica
[0]=>
object(stdClass)#11 (16) {
["item"]=>
int(4962659860)
["user"]=>
int(15049957)
["loc"]=>
string(13) "Zielona góra"
["startts"]=>
int(1420243200)
["endts"]=>
int(1422991944)
["qty"]=>
int(32)
["cat"]=>
int(110497)
["tcat"]=>
int(167159)
["title"]=>
string(50) "ASDASDASDASDASAS"
["curr"]=>
string(3) "zł"
["price"]=>
int(1039)
["len"]=>
int(5853)
["detSt"]=>
int(5235056873762)
["detLen"]=>
int(2439)
["start"]=>
int(93772023807)
["t"]=>
[0]=>
object(stdClass)#12 (5) {
["ts"]=>
int(1422991944)
["qty"]=>
int(1)
["price"]=>
int(1039)
["c"]=>
object(stdClass)#13 (4) {
["id"]=>
int(9200363)
["ts"]=>
int(1427189100)
["text"]=>
string(43) "ASDASDASDASDASDASDSA"
["type"]=>
int(1)
}
["buyer"]=>
int(3484942)
}
[1]=>
object(stdClass)#14 (5) {
["ts"]=>
int(1422991944)
["qty"]=>
int(1)
["price"]=>
int(1039)
["c"]=>
object(stdClass)#15 (4) {
["id"]=>
int(9201391)
["ts"]=>
int(1427016180)
["text"]=>
string(43) "ASDASDASDASDAS"
["type"]=>
int(1)
}
["buyer"]=>
int(2390237)
}
[2]=>
object(stdClass)#16 (5) {
["ts"]=>
int(1422991944)
["qty"]=>
int(1)
["price"]=>
int(1039)
["c"]=>
object(stdClass)#17 (4) {
["id"]=>
int(9209687)
["ts"]=>
int(1425579240)
["text"]=>
string(43) "ASDSADASDASDASDASDAS"
["type"]=>
int(1)
}
["buyer"]=>
int(2635831)
}
Podane klucze:
[0]=>
string(5) "price"
[1]=>
string(5) "buyer"
}
I teraz mam takie cos:
public function recursiveFind
(array $array, $needle) { $iterator = new \RecursiveArrayIterator($array);
$recursive = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($recursive as $key => $value) {
$row->$needle = $value->$needle;
}
}
return $aHitList;
}
Co działa poprawnie (ale dla jednego klucza).
[0]=>
object(stdClass)#654 (1) {
["text"]=>
string(43) "ASDASDASDASDASDASDSA"
}
Dla wielu zwraca tak ze jest pierw lista z pierwszymi kluczami a potem kolejno. A potrzebuje zrobic tak aby otrzymac:
[0]=>
object(stdClass)#654 (1) {
["text"]=>
string(43) "ASDASDASDASDASDASDSA",
["buyer"]=>
string(43) 3484942
}
[1]=>
object(stdClass)#654 (1) {
["text"]=>
string(43) "ASDASDASDASDASDASDSA"
["buyer"]=>
string(43) 2390237
}
Jakies pomysly jak poprawic ten skrypt abym otrzymał takie dane?
Ten post edytował rad11 1.12.2015, 10:17:44