Ver Mensaje Individual
  #4 (permalink)  
Antiguo 09/07/2017, 11:58
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 10 meses
Puntos: 379
Respuesta: Llenar un array completo

Cita:
Aquí mi pregunta: existe alguna forma en donde pueda incluir toooodos los campos en el nuevo array, sin tener que indicarlo uno a uno?
Solo tienes que usar array_filter para obtener a las estudiantes, ejemplo.
Código PHP:
Ver original
  1. $all_students = [
  2.  
  3. ['id' => 1, 'name' => 'Naiara Dominguez Peña', 'sex' => 1],
  4. ['id' => 1, 'name' => 'Jorge Romero Soler', 'sex' => 0],
  5. ['id' => 1, 'name' => 'Miguel Gomez Fuentes', 'sex' => 0],
  6. ['id' => 1, 'name' => 'Noelia Moya Lopez', 'sex' => 1],
  7. ['id' => 1, 'name' => 'Miguel Gil Saez', 'sex' => 0],
  8. ['id' => 1, 'name' => 'Jana Cano Medina', 'sex' => 1],
  9. ['id' => 1, 'name' => 'Marco Gonzalez Duran', 'sex' => 0],
  10. ['id' => 1, 'name' => 'Carlos Puig Hernandez', 'sex' => 0],
  11. ['id' => 1, 'name' => 'Jordi Romero Santana', 'sex' => 0],
  12. ['id' => 1, 'name' => 'Nora Leon Mendez', 'sex' => 1],
  13.  
  14. ];
  15.  
  16. $girl_students = array_filter($all_students, function($student) {
  17.     return $student['sex'] == 1;
  18. });
  19.  
  20. print_r($girl_students);
Esto imprime lo siguiente
Código PHP:
Ver original
  1. (
  2.     [0] => Array
  3.         (
  4.             [id] => 1
  5.             [name] => Naiara Dominguez Peña
  6.             [sex] => 1
  7.         )
  8.  
  9.     [3] => Array
  10.         (
  11.             [id] => 1
  12.             [name] => Noelia Moya Lopez
  13.             [sex] => 1
  14.         )
  15.  
  16.     [5] => Array
  17.         (
  18.             [id] => 1
  19.             [name] => Jana Cano Medina
  20.             [sex] => 1
  21.         )
  22.  
  23.     [9] => Array
  24.         (
  25.             [id] => 1
  26.             [name] => Nora Leon Mendez
  27.             [sex] => 1
  28.         )
  29.  
  30. )
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.