problem: extract data object/array , represent data using multidimensional array unique key generated inner loop.
i find myself building multidimensional arrays this:
$final_array = array(); foreach ($table $row) { $key = null; $data = array(); foreach ($row $col => $val) { /* logic goes here data transformation / concatenation stuff */ if ($col=='my_unique_key_name') { $key = $val; } $data[$col] = $val; } if (!is_null($key) { if (!isset($final_array[$key]) { $final_array[$key] = array(); } $final_array[$key][] = $data; } } i can't wonder if i'm doing out of habit, feels kind of verbose key-checking , whatnot. there native function not utilizing? can refactored more simple or overthinking this?
why doing that? doesn't seem common kind of stuff 1 works on day day basis... anyway, that's kinda cryptic (an example nice) have though of using md5 hash of serialized dump of array uniquely define key?
$key = md5(serialize($value));
Comments
Post a Comment