NockyGo

爱代码,爱生活

a=none 后面为none解析不出来

sample.ini

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

##

[s1]

a=1

b=1

c=1

#d=1

e=fa#1

h = kda dawda

ddaw=

dwada

dwaihduihawu=dwadwa #dwa

[s2]

f=1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

//would see the version,php5.3 和大于php5.3

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

//parse_ini_file解析出来的数组不一致,使用以下方法可解决

$ini_array = parseconfig($ini_array);

print_r($ini_array);

function parseconfig($arr){

// print_r($arr);

if(count($arr)>0){

foreach ($arr as $k => $v) {

if(is_array($v)){

$arr[$k] = parseconfig($v);

}else{

$pos = stripos($v," #");

if($pos!==false){

$arr[$k] = substr($v, 0,$pos);

}

if(substr(trim($k),0,1)=='#'){

unset($arr[$k]);

}

}

}

}

return $arr;

}

二维数组分组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$defaultrules = array(
'id'=>1,'studioid'=>5,
'id'=>2,'studioid'=>5,
'id'=>3,'studioid'=>2,
'id'=>4,'studioid'=>3
);

$rule = [];//rule 拆分数组
foreach($defaultrules as $de){
if(isset($rule[$de['studioid']])){
array_push($rule[$de['studioid']],$de['id']);
}else{
$rule[$de['studioid']] = array($de['id']);
}
}
$rule = array(
5=>array(1,2),
2=>array(3),
3=>array(4)
);
0%