Using the PHP Function pg_field_Table
PHP supports a number of built-in functions for you to use in your code. These can help you accomplish a wide range of tasks quickly and easily. The pg_field_table function is one of these. It returns an array containing all rows (records) in a query result resource. The mode parameter controls how the array is indexed; if it is set to PGSQL_ASSOC, then the returned array will contain only associative indices, whereas if it is set to PGSQL_NUM, it will return only numerical indices.
The first thing to notice about the function definition above is that it expects two parameters. These are called arguments, and they are specified after the function name within parenthesis. Arguments can be any type of variable, and they are passed to the function by value. In other words, a copy of the argument is used inside the function, and the original variable remains unchanged outside of the function.
For example, in the second call to optionalDemo, the value of $fruit is used both inside and outside of the function, despite the fact that it represents a different value or memory space inside and outside the function. This has to do with the way that variables are scoped in PHP.
In order to ensure that a variable has the same meaning in both places, you can use the global keyword. When you use a global variable, an entry is added to the PHP symbol table that refers to an internal data structure representing the variables value. This makes the variable visible both inside and outside of the function, which is useful when you want to make sure that your code is consistent across multiple instances of the script.