Created
December 29, 2014 16:24
-
-
Save porfidev/81c46f2b44c15646ea64 to your computer and use it in GitHub Desktop.
Crea un arreglo, donde se debe tomar la fecha mas reciente y la final
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: Porfirio | |
* Date: 29/12/2014 | |
* Time: 09:22 AM | |
*/ | |
$array = array( | |
array("id" => '1', 'Fecha' => '12/12/2014'), | |
array("id" => '1', 'Fecha' => '13/12/2014'), | |
array("id" => '1', 'Fecha' => '14/12/2014'), | |
array("id" => '2', 'Fecha' => '10/11/2014'), | |
array("id" => '2', 'Fecha' => '11/11/2014'), | |
array("id" => '2', 'Fecha' => '12/11/2014'), | |
array("id" => '5', 'Fecha' => '05/10/2014'), | |
array("id" => '5', 'Fecha' => '06/11/2014'), | |
array("id" => '5', 'Fecha' => '07/11/2014') | |
); | |
## Ordenarlo | |
$arrayToSort = array(); | |
foreach($array as $index){ | |
$arrayToSort[$index["id"]]["id"] = $index["id"]; | |
$arrayToSort[$index["id"]]["fechas"][] = $index["Fecha"]; | |
} | |
var_dump($arrayToSort); | |
## Crear un array con los valores ordenados y legibles | |
$finalArray = array(); | |
foreach($arrayToSort as $index){ | |
$temp = array( | |
"id" => $index["id"], | |
"fechaInicial" => reset($index["fechas"]), | |
"fechaFinal" => end($index["fechas"]) | |
); | |
$finalArray[] = $temp; | |
} | |
var_dump ($finalArray); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment