-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.php
More file actions
51 lines (48 loc) · 1.36 KB
/
1.php
File metadata and controls
51 lines (48 loc) · 1.36 KB
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
50
51
<?php
header("Content-type:text/html; charset=utf-8");
$a = Array(0 => Array('fathername' => '全部'),
546 => Array
(
'fathername' => '智能手机',
'fatherid' => 546,
'child' => Array
(
0 => Array
(
'value' => '华为',
'id' => '550',
),
1 => Array
(
'value' => 'oppo',
'id' => '561',
),
2 => Array
(
'value' => '三星',
'id' => '547',
)
)
)
);
$info = array();
$i = 0;
foreach($a as $k=> $v){
$info[$i] = getParentCat($v);
$i++;
}
var_dump($info);
function getParentCat($array){
$product = array();
$sql = sprintf("select pid,cat_name from blog_category where cid=%d limit 1", $array['fatherid']);
$q = mysql_query($sql);
$row = mysql_fetch_array($q, MYSQL_ASSOC);
if($row['pid'] !=0){
$product['fathername'] = $row['cat_name'];
$product['fatherid'] = $row['pid'];
$product['cat_ids'] = $array;
getParentCat($product);
}else{
return $product;
}
}