PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular

mysqli_fetch_array

Tags: PHP 5.x PHP 7.x PHP 8.x

mysqli_fetch_array — Fetch a result row as an associative, a numeric array, or both.

Description

mysqli_fetch_array(
    mysqli_result $result,
int $mode = MYSQLI_BOTH
): array|null|false
Returns an array that corresponds to the fetched row or null if there are no more rows for the result set. In addition to storing the data in the numeric indices of the result array, this function can also store the data in associative indices by using the field names of the result set as keys.

Note: Field names returned by this function are case-sensitive.

Note: This function sets NULL fields to the PHP null value.



If two or more columns of the result have the same field names, the last column will take precedence and overwrite the earlier data. In order to access multiple columns with the same name, the numerically indexed version of the row must be used.

Parameters

result
Procedural style only: A mysqli_result object returned by mysqli_query(), mysqli_store_result(), mysqli_use_result() or mysqli_stmt_get_result().
mode
This optional parameter is a constant indicating what type of array should be produced from the current row data. The possible values for this parameter are the constants MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH. By using the MYSQLI_ASSOC constant this function will behave identically to the mysqli_fetch_assoc(), while MYSQLI_NUM will behave identically to the mysqli_fetch_row() function. The final option MYSQLI_BOTH will create a single array with the attributes of both.

Return Values

Returns an array of values that corresponds to the fetched row or null if there are no more rows in result set.

mysqli_fetch_array - New snippets