作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
new Vector ("08:00:00","08:30:00","sa-6ren">
我想知道如何创建这个数组
$datos = new ArrayIterator(array(
"08:00:00" => new Vector ("08:00:00","08:30:00","sandrad"),
"10:00:00" => new ArrayIterator (array( "10:00:00", "10:45:00", "palomas" )),
"20:00:00" => new Vector("20:00:00","21:15:00","pedrales"),
"25:30:00" => new ArrayIterator ( .....etc....
))
这是我的查询以及我是如何尝试的:
$sql = "SELECT * FROM amigos WHERE fecha='$fecha' AND ORDER BY hora_inicio ASC ";
$result = mysql_query($sql) or die(mysql_error());
$totalRows = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
switch ($funcion) {
case 'new Vector (':
$funcion='new ArrayIterator (array(';
break;
case 'new ArrayIterator (array(':
$funcion ='new Vector (';
break;
default:
$funcion ='new Vector (';
}
switch ($fin_funcion) {
case '),':
$fin_funcion = ')),';
break;
case ')),':
$fin_funcion = '),';
break;
default:
$fin_funcion = '),';
}
$datos=new ArrayIterator(array(
$row['hora_inicio'] => $funcion.'"'.$row['hora_inicio'].'","'.$row['hora_final'].'","'.$row['nombre'].'"'.$fin_funcion
));
}
但我运气不好。有什么想法吗?
最佳答案
您每次通过循环都会创建一个新的 $datos ArrayIterator。如果您想要一个 ArrayIterator,请创建整个数组,然后对其进行初始化。
$datos = array();
while($row=mysql_fetch_assoc($result)){
switch($funcion){
case 'new Vector (':
$funcion='new ArrayIterator (array(';
break;
case 'new ArrayIterator (array(':
$funcion ='new Vector (';
break;
default:
$funcion ='new Vector (';
}
switch($fin_funcion){
case '),':
$fin_funcion = ')),';
break;
case ')),':
$fin_funcion = '),';
break;
default:
$fin_funcion = '),';
}
$datos[$row['hora_inicio']] = $funcion.'"'.$row['hora_inicio'].
'","'.$row['hora_final'].'","'.$row['nombre'].'"'.$fin_funcion;
}
$datos = new ArrayIterator($datos);
关于php - 我如何从 mysql 查询创建这个数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5307662/
我是一名优秀的程序员,十分优秀!