PHP mysqli_fetch_array() Function

PHP mysqli_fetch_array() function is used to fetch results row as an associative, a numeric array, or both.

Syntax

array mysqli_fetch_array(result, resulttype);

mysqli_fetch_array() Function Parameter

ParameterDescription
result :Required parameter. Mention a result set identifier returned by mysqli_query().
resulttype :Optional paramater. Mention type of array that should be generated. The resulttype could be MYSQLI_ASSOC or MYSQLI_NUM or MYSQLI_BOTH.

mysqli_fetch_array() Function Return Value

Return Values :Returns an array of strings that corresponds to the fetched row, or FALSE if there are no more rows.

mysqli_fetch_array() Function Example

<?php
$con = mysqli_fetch_arrayt("localhost","user","password","db");

if (mysqli_connect_errno())
{
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql = "SELECT fname, lname FROM employee";
$sql_result = mysqli_query($con, $sql);

while ($row = mysql_fetch_array($sql_result, MYSQL_NUM)) {
    echo "First Name : ". $row["fname"] . " Last Name : ". $row["lname"];  
}

mysql_free_result($sql_result);

mysqli_close($con);
?>