4
Well I have the following array:
$produtos2[] = array(
"cod" => (int) 768,
"nome" => "LOGITECH M535",
"GRUPO" => "MOUSE"
);
$produtos2[] = array(
"cod" => (int) 2334,
"nome" => "MULTILASER DECT",
"GRUPO" => "TECLADO"
);
$produtos2[] = array(
"cod" => (int) 334,
"nome" => "PANASONIC DECT",
"GRUPO" => "MOUSE"
);
$produtos2[] = array(
"cod" => (int) 3334,
"nome" => "APPLE DECT",
"GRUPO" => "TECLADO"
);
$produtos2[] = array(
"cod" => (int) 234,
"nome" => "SAMSUNG D499",
"GRUPO" => "MOUSE"
);
To list the result of the array I do so:
// Navega pelos elementos do array
foreach ($produtos as $c) {
echo $c['nome']."<br>";
}
The result is:
LOGITECH M535
MULTILASER DECT
PANASONIC DECT
APPLE DECT
SAMSUNG D499
Good what I need is to separate the products of have the same group and list them coming across by group, example:
MOUSE
LOGITECH M535
PANASONIC DECT
SAMSUNG D499
TECLADO
MULTILASER DECT
APPLE DECT
I have no idea how to do this.
you can create other array (by group) and add data from the main array to them according to the group or turn into a json and resolve in the front-end
– Costamilam
Well that’s a good idea, I can run the product array capturing the groups, but how to avoid group duplicity?
– Hugo Borges
Is the group property dynamic? for example can be created one more at any time (daai complicates a little) or are fixed options (in this case just create
array_teclado
andarray_mouse
and go through the main array by passing the items, it would be interesting to remove these items from the main array, not to read more data unnecessarily)– Costamilam
It is dynamic, are various products with several different groups.
– Hugo Borges
you have some table in the bank where these groups are registered or the user type in a
input
text group you want?– Costamilam
the user type in a text input.
– Hugo Borges