The PHP Function SQLSRV_FetchArray
PHP has more than 1000 built-in functions that can be used to perform specific tasks. Each function has a different purpose, but the common feature is that they execute a set of statements within a script when called. Functions are a great way to keep code organized and reduce repetitive commands. In this article, we will look at a popular php function called sqlsrv_fetch_array.
This function retrieves a subsequent set of data row information as either an associative array or a numeric array, or a combination of both. The row information is returned from a variable that holds a statement resource matching with an executed statement. The first data row in the result set has index 0.
Unlike a variable in PHP, a function return value is not assigned a data type. Unless you explicitly indicate the intended data type with a Kind Declaration, PHP will automatically assign the return value a data form that it understands. You can prevent this by using the Kind Declaration feature, introduced in PHP 7.
If you want to retrieve field names for a row, you have to use sqlsrv_get_field() instead of sqlsrv_fetch_array(). This function is consistent in that it provides data based on the Default PHP Data Types. When retrieving a nameless field, the associative key for the array element will be an empty string ("").
This is just a small sample of the many useful php functions that you can use to create your own applications. For more detailed information about the different types of php functions, you can check out the PHP Manual.