Foros del Web » Programando para Internet » PHP »

PHP OO Como podria agrupar este array en PHP

Estas en el tema de Como podria agrupar este array en PHP en el foro de PHP en Foros del Web. Yo tengo este array : Código PHP:   array( 3 ) {   [ 0 ]=>   array( 5 ) {     [ "alu_id" ]=>      string ( 10 )  ...
  #1 (permalink)  
Antiguo 16/08/2015, 13:31
 
Fecha de Ingreso: agosto-2015
Mensajes: 1
Antigüedad: 8 años, 8 meses
Puntos: 0
Pregunta Como podria agrupar este array en PHP

Yo tengo este array :
Código PHP:
 array(3) {
  [
0]=>
  array(
5) {
    [
"alu_id"]=>
    
string(10"2015100100"
    
["nombres"]=>
    
string(29"Vargas Gonzales Maritza Rocio"
    
["mat_id"]=>
    
string(2"27"
    
["cri_id"]=>
    
string(2"EP"
    
["not_nota"]=>
    
string(2"12"
  
}
  [
1]=>
  array(
5) {
    [
"alu_id"]=>
    
string(10"2015100100"
    
["nombres"]=>
    
string(29"Vargas Gonzales Maritza Rocio"
    
["mat_id"]=>
    
string(2"27"
    
["cri_id"]=>
    
string(2"EF"
    
["not_nota"]=>
    
20
  
}
  [
2]=>
  array(
5) {
    [
"alu_id"]=>
    
string(10"2015100133"
    
["nombres"]=>
    
string(29"Pedro Javier Lopez"
    
["mat_id"]=>
    
string(2"28"
    
["cri_id"]=>
    
string(2"EP"
    
["not_nota"]=>
   
13
  

Quiero agruparlos y que me quede asi:

Código PHP:
    [0] => 
       
alu_id
      nombres
      mat_id
      
["notas"] =>
         [
0] =>
             
cri_id
             not_nota
         
[1]  =>
            
cri_id
            not_nota
   
[1] => 
       
alu_id
      nombres
      mat_id
      
["notas"] =>
         [
0] =>
             
cri_id
             not_nota
         
[1]  =>
            
cri_id
            not_nota 
Agrupando por el alu_id

Última edición por AlanLelouch; 16/08/2015 a las 13:33 Razón: Falto colocar mas informacion
  #2 (permalink)  
Antiguo 16/08/2015, 15:34
(Desactivado)
 
Fecha de Ingreso: abril-2015
Ubicación: España
Mensajes: 616
Antigüedad: 9 años
Puntos: 74
Respuesta: Como podria agrupar este array en PHP

Sería algo así:

Código PHP:
Ver original
  1. $array = array();
  2. foreach($miarray as $element):
  3.          $array2 = array();
  4.          $array2['alu_id'] = $element['alu_id'];
  5.          $array2['nombres'] = $element['nombres'];
  6.          $array2['mat_id'] = $element['mat_id'];
  7.          $array3 = array();
  8.          $array3[0] = $element['cri_id'];
  9.          $array3[1] = $element['not_nota'];
  10.          $array2['notas'] = $array3;
  11.          $array[] = $array2;
  12. endforeach;
  13. var_dump($array);

Etiquetas: php+arrays
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:43.