我需要我的 for 循环来返回一个看起来像这样的数组
$nullArray =array(
0 => array("id" => 1, "label" => "test 1", "type" => "folder"),
array("id" => 2, "label" => "test 2", "type" => "folder"),
array("id" => 3, "label" => "test 3", "type" => "folder"),
etc...
etc...
etc...
);
我现在拥有的
$nullArray = array();
$numOfVer = mysql_num_rows($result);
$startArray= array();
//SETS FIRST NODE
for($i =0;$i < $numOfVer;$i++)
{
$label = mysql_result($result, $i);
$id = $i+1;
$startArray = array(array('id' => $id,'label' => $label, "type" => "folder"));
//$startArray[]['id'] = $id;
//$startArray[]['label'] = $label;
//$startArray[]['type'] = "folder";
//array_push($startArray,array(array('id' => $id,'label' => $label, "type" => "folder")));
//$nullArray[0]= array(array('id' => $id,'label' => $label, "type" => "folder"));
//array_push($nullArray[0],array('id' => $id,'label' => $label, "type" => "folder"));
}
$nullArray[0] = $startArray;
echo json_encode($nullArray[0]);
我注释掉的所有内容都是我尝试过的,但都失败了。我已经为这么简单的事情做了太久了,所以我决定寻求帮助!先感谢您!:)