I have a database table for User in that i have two fields USER_ID and USER_DESCRIPTION, If i run the bellow code i get array in the form.
Array ( [USER_ID] => 1 [USER_DESCRIPTION] => TAB )
But i want to access those value in index based like 0, 1.How to i get that.
while (($result = oci_fetch_array($data, OCI_ASSOC)) != false) {
echo $result['USER_ID']. ' - ' .$result['USER_DESCRIPTION']; //This works
echo $result[0]. ' - ' .$result[1]; //This is how i want to access the values
}
Access Array Elements Array indexing is the same as accessing an array element. You can access an array element by referring to its index number. The indexes in NumPy arrays start with 0, meaning that the first element has index 0, and the second has index 1 etc.
Accessing Elements in a PHP Array The elements in a PHP numerical key type array are accessed by referencing the variable containing the array, followed by the index into array of the required element enclosed in square brackets ([]).
PHP indexed array is an array which is represented by an index number by default. All elements of array are represented by an index number which starts from 0. PHP indexed array can store numbers, strings or any object. PHP indexed array is also known as numeric array.
We can access elements of an array using the index operator [] . All you need do in order to access a particular element is to call the array you created. Beside the array is the index [] operator, which will have the value of the particular element's index position from a given array.
You have passed second parameter OCI_ASSOC
to oci_fetch_array()
which will fetch only associative array.
If you change that parameter to OCI_BOTH
, it will return both numeric as well associative array.
OCI_BOTH
is default. So, even you can put that parameter empty.
Change
while (($result = oci_fetch_array($data, OCI_ASSOC)) != false) {
To
while (($result = oci_fetch_array($data, OCI_BOTH)) != false) {
OR To (as OCI_BOTH
is default):
while (($result = oci_fetch_array($data)) != false) {
Read it here:
http://php.net/manual/en/function.oci-fetch-array.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With