I am trying to create a array with three dimensions. first let me explain how my data is coming. my current data
Array
(
[0] => stdClass Object
([1] => A [2] => a [3] => *)
[1] => stdClass Object
([1] => A [2] => a [3] => $)
[2] => stdClass Object
([1] => B [2] => a [3] => %)
[3] => stdClass Object
([1] => B [2] => b [3] => @)
[4] => stdClass Object
([1] => B[2] => c[3] => x)
- Capital letters are my main Heading
- Small letters are my sub heading
- symbols are my sub sub heading
What i want:
Array
(
[0] => A(
[0] => a(
[0] => *
[1] => $
)
)
[1] => B
(
[0] => a(
[0] => %
)
[1] => b(
[0] => $
)
[2] => c(
[0] => x
)
)
So first i have to remove duplicate heading make array of them and then add more array values SO here i have done so far and don't know where to go
Code:
$query = $this->db->get();
$raw_data = $query->result();
//$array = json_decode(json_encode($data), true);
$data = array();
echo "<pre>";
foreach ($raw_data as $key => $value) {
if (in_array($value->DEPT, $data) != 1) {
$data[] = $value->DEPT;
}
}
//for here no idea what to do
foreach ($raw_data as $key => $value) {
$d_key = array_search($value->DEPT, $data[$d_key]);
if (in_array($value->CAT, $data) != 1) {
$data[$d_key] = [$value->CAT];
}
}
print_r($data);
echo "</pre>";
I have remove duplication new i want to add sub heading in main heading array