I try to modify one of the data of array
that I get from a query to BD
, before passing it to JSON
, but I do not get it, I access the value in a foreach
but I do not know how to change the data
array (1) {["data"] = > array (2) {[0] = > array (8) {["id"] = > string (1) "3" ["customer_name"] = > string (8) "Cristina" ["customer_surname1"] = > string (9) "Martínez" ["customer_surname2"] = > string (10) "Fernández" ["born_date"] = > string (10) "1980-03-02" ["wish"] = > string (1) "1" ["type"] = > string (7) "Study" ["start"] = > string (19) "2017-12-19 17:00:00"} [1] = > array (8) {["id"] = > string (2) "78" ["customer_name"] = > string (8) "Hector" ["customer_surname1"] = > string (6) "Arraiz" ["customer_surname2"] = > string (4) "Something" ["born_date"] = > string (10) "1985-11-10" ["wish"] = > string (1) "1" ["type"] = > string (8) "Exterior" ["start"] = > string (19) "2017-12-21 17:00:00"}}}
$sql = "SELECT customers.id,'customer_name','customer_surname1','customer_surname2','born_date','wish', type_event.type, events.start FROM 'customers' INNER JOIN event_has_customers on customers.id = customer_id left JOIN events on event_id = events.id LEFT JOIN type_event on events.id = type_event.id";
$result = $mysqli->query($sql);
if($mysqli->errno) die($mysqli->error);
$response["data"]=array();
while($registros = $result->fetch_assoc()){
$response["data"][]=$registros;
}
//aquí llego a la fecha
foreach ($response as $key => $value) {
foreach ($value as $k => $v) {
var_dump(formatDte($v['start']));//aquí cambia el formato
}
}
echo json_encode($response);//start sigue en su formato original
function formatDte($cdn){
$array = explode(' ', $cdn);
return $array[0];
}