I have an array and want to create a new numeric array. This looks like this:
$created_old = explode("_", $result[$i]["created"]);
$created_new = array();
$created_new[0] = $created_old[2];
$created_new[1] = $created_old[0];
$created_new[2] = $created_old[1];
$created_new[3] = "";
$created_new[4] = rtrim(explode(":", $created_old[3])[2], ")");
//Get name from the database
$created_new[3] = $name;
$created = implode("_", $created_new);
This version works just fine, but the previous was missing one line, so the code would be this:
$created_old = explode("_", $result[$i]["created"]);
$created_new = array();
$created_new[0] = $created_old[2];
$created_new[1] = $created_old[0];
$created_new[2] = $created_old[1];
//$created_new[3] = ""; - I am missing
$created_new[4] = rtrim(explode(":", $created_old[3])[2], ")");
//Get name from the database
$created_new[3] = $name;
$created = implode("_", $created_new);
In the second code the string $created
is in the wrong order. The index 4 and 3 are switched. If it would be an associative array I would understand this but as it is an numeric array I assume the indices to increase numerically and beeing ordered like this. As I have a working version I do not need help to fix this code but rather understand why the code behaves as it does...
Best regards JRsz