I have an array that displays it's keys and values twice. Here is an example of the way it displays data:
Array (
[0] => 38
[1] => 38
[2] => 10
[3] => 10
[4] => B
[5] => B
[6] => 5
[7] => 5
[8] => 5
[9] => 5
[10] => 5
[11] => 5
[12] => 5
[13] => 5
[14] => 5
[15] => 5
[16] => 5
[17] => 5
[18] => 5
[19] => 5
)
I tried looking for a solution on SO but I only found cases with for each. Tried selecting only even keys but haven't managed to do that. array_unique() wouldn't work in my case since there is a chance that I have equal values for different fields.
What could be the problem that causes it to display twice?
<?php
include_once "connect.php";
$intrebare_02 = mysqli_real_escape_string($con, $_POST['intrebare_02']);
$i = 0;
$array_sum=[];
while ($i < 10){
$i++;
$sql = "SELECT * FROM parteneri WHERE nr_intrebare = '$i' AND varianta_raspuns = '$intrebare_02'";
$result = mysqli_query($con, $sql);
$final_array = array();
if ($i % 2 == 0)
while ($row = mysqli_fetch_array($result))
{
$final_array = array_values($row);
$array_sum = array_map(function () {
return array_sum(func_get_args());
}, $array_sum, $final_array);
}
}
print_r($final_array);
Let me know if you need further clarification.
[1,3,5]to[1,1,3,3,5,5]?$row = mysqli_fetch_array($result, MYSQLI_NUM).... and then you don't need to do thatarray_values()call either