I would like to create a JSON object dynamically. The JSON object will have to be as the follows:
{
$capa:[$fila['test_name'],...etc],
.
.
.etc
};
The key and value will be retrieved through a MySQL query.
This is what i'm doing:
$array_container= array();
while($fila=mysqli_fetch_assoc($sql)){
$format_org=str_replace(" ","_",$fila["organization"]);
$format_eval=str_replace(" ","_",$fila["EvaluationType"]);
$format_test=str_replace(" ","_",$fila["test_name"]);
$CapaEnviar=$format_org.$format_eval;
$array_container[] = array($CapaEnviar => $fila['test_name']);
}
echo json_encode($array_container,true);
Using the previous code, I can retrieve a JSON object with duplicate keys.
This code is an answer for an AJAX request, so once the JSON object has been created correctly, I will send back this JSON object in order to retrieve the key and value, so I will have to retrieve separately the key and value.
$array_container[] = array($CapaEnviar => $fila['test_name']);should be$array_container[] = array($CapaEnviar => $format_test);, don't you think?