PHP多维数组
/***************************by
garcon1986********************************/
一个三维数组的显示,保存以备以后使用。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
error_reporting(E_ALL ^ E_NOTICE);
$conn = mysql_connect("localhost","charles","charles");
mysql_select_db("crm1204", $conn);
//为了更好的显示for better display
function dump($vars, $label = null, $return = false) {
if (ini_get('html_errors')) {
$content = "<pre>\n";
if ($label !== null && $label !== '') {
$content .= "<b>{$label} :</b>\n";
}
$content .= htmlspecialchars(print_r($vars, true));
$content .= "\n</pre>\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(&quo
相关文档:
还是
部门无聊的考题,不过这次考的是 PHP
的能力。题目如下:
给你两个分别有 5000 个元素的数组,计算他们的差集
-- 说白了也就是用 PHP 和你认为最好的算法实现 array_diff 的算法。
初次接到这个题目,我发现这非常的简单,
于是按照以往的经验“随便”写了一个:
function array_diff($array_1, $ ......
/***************************by
garcon1986********************************/
<?php
//if 语句
$a = $b = 3;
if($a = $b)
print "a is equal to b<br>";
//else 语句
if($a < $b){
print "a is smaller than b";
} else {
print "a is not smaller than b<br> ......
/*********************************************************************************************
*****************************php二级联动菜单改动版***********************************
****************************************by garcon1986*****************************************
********************* ......