— PHP-Developer, . ( page views ). 2 . , , ( , ). 10 . .
, . , … , . .
? -, - ; -, -, , ; -, - ?
— . , .
PHP assignment
Write a function, read_conf($filename), that converts the configuration below into a multidimensional array.
The configuration is divided up in rows and each row is divided up by key and value. The key can be multidimensional, and can be from 1...N, in the example below we only have 4 levels, but the solution should be able to work even when adding another row with more key levels: eg. session.save.db.master.host=10.0.0.1
===config.txt===
id=www
session.timeout=120
session.server.0.host=127.0.0.1
session.server.0.port=1111
session.server.0.id=session1
session.server.1.host=127.0.0.1
session.server.1.port=1111
session.server.1.id=session2
image.width=640
image.height=480
image.watermark.small=wsmall.png
image.watermark.normal=wnormal.png
===code===
<?php
$res = read_conf(«config.txt»);
var_dump($res);
?>
===output===
array(3) {
["id"]=>strong(3) "www"
["session"]=>array(2) {
["timeout"]=>string(3) "120"
["server"]=>array(2) {
[0]=>
array(3) {
["host"]=>
string(9) "127.0.0.1"
["post"]=>
string(4) "1111"
["id"]=>
string(8) "session1"
}
[1]=>
array(3) {
["host"]=>
string(9) "127.0.0.1"
["port"]=>
string(4) "1111"
["id"]=>
string(8) "session2"
}
}
}
["image"]=>
array(3) {
["width"]=>
string(3) "640"
["height"]=>
string(3) "480"
["watermark"]=>
array(2) {
["small"]=>
string(10) "wsmall.png"
["normal"]=>
string(11) "wnormal.png"
}
}
}