0

I wrote a program to skim log files and pass the information into an ini file and I'm trying to do some php work with it, I have 0 experience with php.

I have an INI file that contains information like so,

[76561197962467705]
Username = ".buckisM"
Suicide = 0
bear.prefab = 0
killed by fall = 0
patrolhelicopter.prefab = 0
wolf.prefab = 0
Cold = 0
Explosion = 0
barricade = 0
Player Deaths = 0
Total Deaths = 0
Kills = 2

I use the php ini parser and can get the ini to print to a webpage.

    $ini_array = parse_ini_file("myfile.ini", true);
    print_r($ini_array);

The printed array. http://liveviewtest.byethost7.com/index.php

From what I have read parse_ini_file parses the information into a multidimensional array if the true flag is set. Why cant I access the array elements using brackets?

echo $ini_array[0][0];
1
  • What you are trying to fetch from this array' Commented Sep 21, 2015 at 6:29

2 Answers 2

1

Because what you got is actually a dictionary, which is a non ordered array. You can't address each element of that structure by a numeric index, since it is indexed with the keys defined in the ini file. You address it like

$ini_array['76561197988912576']['username']

You can cycle with a foreach loop

foreach($ini_array as $key=>$value) {
  echo ($value['username']);
}

Or you can convert your dictionary into an indexed array with "array_keys"

$ini_array = array_keys($ini_array);
echo $ini_array[0]['username'];
Sign up to request clarification or add additional context in comments.

1 Comment

Is there no way to cycle through it? The ini file is continually growing and the numbers constantly changing.
0

Because in this case you have hash with string keys. For example if you want get first Username from this array you can try this code:

var_dump($ini_array['76561197988912576']['Username']);

I hope it help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.