php多维数组签名,PHP多维数组

/***************************by garcon1986********************************/ 一个三维数组的显示,保存以备以后使用。 !DOCTYPE htmlhtmlhead/headbody?phperror_reporting(E_ALL ^ E_NOTICE);$conn = mysql_connect(localhost,charles,charles);mysql_se

/***************************by

garcon1986********************************/

一个三维数组的显示,保存以备以后使用。

/n";

if ($label !== null && $label !== '') {

$content .= "{$label} :/n";

}

$content .= htmlspecialchars(print_r($vars, true));

$content .= "/n/n";

}

else {

$content = "/n";

if ($label !== null && $label !== '') {

$content .= $label . " :/n";

}

$content .= print_r($vars, true) . "/n";

}

if ($return) {

return $content;

}

echo $content;

return null;

}

/* 不好的例子

$query = "select * from entreprise";

$result = mysql_query($query);

while($row = mysql_fetch_assoc($result)){

$query2 = "select * from site where entreprise_id = $row[entreprise_id]";

$result2 = mysql_query($query2);

$a2 = array();

while($row2 = mysql_fetch_assoc($result2)){

$query3 = "select * from salarie where site_id = $row2[site_id]";

$result3 = mysql_query($query3);

while($row3 = mysql_fetch_assoc($result3)){

$a3[] = array("text"=>$row3[nom]);

}

if($a3[site_id] == $a2[site_id]){

$a2[] = array("text"=>$row2[nom],'children'=>$a3);

}

}

if($a2[entreprise_id] == $a1[entreprise_id]){

$a1[] = array("text"=>$row[id]." ".$row[nom],'children'=>$a2);

}

}

//print_r($a1);

//echo json_encode($a1);

dump($a1);

*/

$entreprise_q = mysql_query("select * from entreprise");

$site_q = mysql_query("select * from site");

$salarie_q = mysql_query("select * from salarie");

$result = array();

$entreprise = array();

$site = array();

$salarie = array();

while($row = mysql_fetch_assoc($salarie_q)){

if(!is_array($salarie[$row['site_id']])){

$salarie[$row['site_id']] = array();

}

$salarie[$row['site_id']][$row['salarie_id']] = $row['nom'];

}

while($row = mysql_fetch_assoc($site_q)){

if(!is_array($site[$row['entreprise_id']])){

$site[$row['entreprise_id']] = array();

}

$site[$row['entreprise_id']][$row['site_id']] = array(

'name' => $row['nom'],

'salarie' => $salarie[$row['site_id']]

);

}

while($row = mysql_fetch_assoc($entreprise_q)){

if(!is_array($entreprise[$row['entreprise_id']])){

$entreprise[$row['entreprise_id']] = array();

}

$entreprise[$row['entreprise_id']] = array(

'name' => $row['nom'],

'sites' => $site[$row['entreprise_id']]

);

}

//echo json_encode($entreprise);

dump($entreprise);

?>

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值