William
William

Reputation: 477

How to 'decode' array?

I have an .ini file. This is what an .ini file looks like:

[something]
a = b
c = d
e = f
g = h

I have the following PHP code:

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

The output is:

Array
(
    [something] => Array
        (
            [a] => b
            [c] => d
            [e] => f
            [g] => h
        )

)

Is there a way to 'decode' the array? For example, that the output is this:

a => b
c => d
e => f
g => h

Thanks!

Upvotes: 0

Views: 118

Answers (2)

mpgn
mpgn

Reputation: 7251

Like this :

$ini = parse_ini_file("data.ini", true);


foreach ($ini['something'] as $key => $value) {
    echo $key . " => ". $value."<br />";
}

OUTPUT

a => b
c => d
e => f
g => h

Upvotes: 4

prashant thakre
prashant thakre

Reputation: 5147

Its same as mentioned in php page

<?php
$fruit = array('a' => 'apple', 'b' => 'banana', 'c' => 'cranberry');

reset($fruit);
while (list($key, $val) = each($fruit)) {
    echo "$key => $val\n";
}
?>

Upvotes: 0

Related Questions