PHP | mysqli_fetch_array() Function Last Updated : 23 Apr, 2020 Comments Improve Suggest changes Like Article Like Report The mysqli_fetch_array() function is used to fetch rows from the database and store them as an array. The array can be fetched as an associative array, as a numeric array or both. Associative arrays are the arrays where the indexes are the names of the individual columns of the table. On the other hand, numeric arrays are arrays where indexes are numbers, with 0 representing the first column and n-1 representing the last column of an n-column table. Syntax: mysqli_fetch_array ("database_name", "mode") Parameters: This function accepts two parameters as mentioned above and described below: database_name: It is the database on which operations are being performed. It is a mandatory parameter. mode: It can have three values - MYSQLI_ASSOC, MYSQLI_NUM, and MYSQLI_BOTH. MYSQLI_ASSOC makes the function behave like mysqli_fetch_assoc() function, fetching an associative array, MYSQLI_NUM makes the function behave like mysqli_fetch_row() function, fetching a numeric array while MYSQLI_BOTH stores the data fetched in an array that can be accessed using both column indexes as well as column names. Program: php <?php $conn = mysqli_connect( "localhost", "root", "", "Persons"); // Check connection if (mysqli_connect_errno()) { echo "Database connection failed."; } $sql = "SELECT Lastname, Age FROM Persons ORDER BY Lastname"; $result -> $mysqli -> query($sql); // Numeric array $row = mysqli_fetch_array($conn, MYSQLI_NUM); printf ("%s (%s)\n", $row[0], $row[1]); printf("\n"); // Associative array $row = mysqli_fetch_array($conn, MYSQLI_ASSOC); printf ("%s (%s)\n", $row["Firstname"], $row["Lastname"]); mysqli_close($conn); ?> For the above table, the output will be: Output: A B C D E F G H A B C D E F G H Comment More infoAdvertise with us Next Article PHP | mysqli_fetch_array() Function A ArkadyutiBanerjee Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-MySQL Similar Reads PHP | mysqli_error() Function The mysqli_error() function is used to return the error in the most recent MySQL function call that failed. If there are multiple MySQL function calls, the error in the last statement is the one that is pointed out by the function. Syntax: mysqli_error("database_name") Parameters: This function acce 1 min read PHP array_keys() Function The array_keys() is a built-in function in PHP and is used to return either all the keys of and array or the subset of the keys. Syntax: array array_keys($input_array, $search_value, $strict) Parameters: The function takes three parameters out of which one is mandatory and other two are optional. $i 2 min read PHP | is_array() Function The is_array() is an inbuilt function in PHP. The is_array() function is used to check whether a variable is an array or not. Syntax: bool is_array($variable_name) Parameter: This function accept a single parameter as mentioned above and described below: $variable_name: This parameter holds the vari 2 min read PHP in_array() Function The in_array() function in PHP is a built-in function that is used to check if a specific value exists within an array and returns a boolean result. Returns true if the value is found and false if the value is not found.Syntax:bool in_array(mixed $needle, array $haystack, bool $strict = false)In thi 3 min read PHP array_key_exists() Function The array_key_exists() function in PHP is a built-in function that checks whether a specified key exists in an array. This function is commonly used when working with associative arrays, where keys are explicitly defined, and we need to confirm the presence of a particular key to prevent errors or u 2 min read Like