为什么存储在会话变量中的数组计数加倍?

I have a table which contains the following columns..

database columns

And I stored the data of that table in a session variable

$sql = "SELECT * from `basic_info` where Username='".$user."' and Password='".$pass."'";
$sqlresult = mysqli_query($con,$sql) or die(mysqli_error($con));
$rowCount = mysqli_num_rows($sqlresult);
$currentData = mysqli_fetch_array($sqlresult);

if($rowCount > 0){
    $_SESSION['currentUser'] = $currentData;
}

But whenever i echo the values of the array using below code:

<?php

echo "Welcome {$_SESSION['currentUser'][1]}";
echo "<div name='infoDisplay'>";
echo "<table>";
echo "<tr>";
echo "<td><b>Family Name</b><td>";
echo "<td><b>First Name</b><td>";
echo "<td><b>Middle Name</b><td>";
echo "<td><b>Birthday</b><td>";
echo "<td><b>Contact Number</b><td>";
echo "<td><b>Address</b><td>";
echo "<td><b>Username</b><td>";
echo "<td><b>Password</b><td>";
echo "<td><b>Permission Level</b><td>";
echo "<td></td>";
echo "</tr>";


echo "</table>";
echo "</div>";

echo "Array count: " . count($_SESSION['currentUser']) . "<br/>";

echo "<tr>";
for($rowcount=0; $rowcount<=count($_SESSION['currentUser']);$rowcount++){
    echo "<td>". $_SESSION['currentUser'][$rowcount] . "</td>";
}
echo "</tr>";

?>

the array count is doubled. I only have 9 columns in my database but the result is returning 18 counts. Which why I'm also getting below error:

error

Please let me know your inputs on how can I easily resolve the issue. Thank you very much in advance! Have a great day!

As mentioned in the comments, mysqli_fetch_array returns an array with two elements for each column selected in the query: one element with a numeric key, and one element whose key is the column name. So if you select 9 columns, the array will have numeric keys from 0 to 8, and named keys FamilyName, FirstName, and so on.

The problem you're running into count($_SESSION['currentUser']) counts both of these elements, so it will return 18, not 9. Your for loop then uses this as the limit, so it will try to echo $_SESSION['currentUser'][9] through $_SESSION['currentUser'][17], which don't exist.

The solution to this is to use mysql_fetch_row() instead of mysql_fetch_array(). Or use mysql_fetch_assoc() and use a foreach loop instead of a for loop, which is my normal preference.

FROM THE MANUAL:

mysqli_fetch_array() is an extended version of the mysqli_fetch_row() function. In addition to storing the data in the numeric indices of the result array, the mysqli_fetch_array() function can also store the data in associative indices, using the field names of the result set as keys.

So for each row you return lets say you did select fname,lname from ...

You would get an array for each row like this:-

$row would be 

[0 => 'fred', 'fname' => 'fred', 1 => 'Bloggs', 'lname' => 'Bloggs']

This is the doubling up of columns you are talking about

If you use

mysqli_fetch_array($sqlresult, MYSQLI_ASSOC);

or

mysqli_fetch_assoc($sqlresult);

You will only get the Associative array of column names like :

['fname' => 'fred', 'lname' => 'Bloggs']