I have tried reading parameters from php ini files using parse_ini_file
Here is my code
$param_array=parse_ini_file("test.ini");
print $param_array[0];
print $param_array[1];
Above code returns nothing
test.ini file contains,
[names]
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "http://www.w3schools.com"
Now i need to call the Robert & Peter
If you'd have rather consulted the Manual Pages instead of w3fools , you'd have seen a reliable example where it's shown that the returned array is associative, that is, the names of the properties are the keys of the array.
So instead of
$param_array[0]
you should use
$param_array['me']
to access "Robert"
parse_ini_file
returns an associative array. You are trying to access the fields in your array using numerical indices, but they aren't defined.
Try accessing those fields using the names you gave them in the ini-file as the key:
echo $param_array['me']; // will yield Robert
Helpful tip: investigate the structure of arrays and variables to find out what they look like using print_r
or var_dump
Following code worked!
print $param_array["me"];
print $param_array["you"];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.