PHP arry_push方法使用注意
当在使用arry_push方法向数组中某个子元素中中添加元素时应该注意,如例若使用预定义好的元素push,则会出现以下情况:
这里 "children" => $nodeList 与 array_push($bladeList[0][‘children‘],$nodeList);得到的结果不同!
$bladeList = array(); $nodeList = array(); array_push($nodeList, array( "text" => ‘test’, "status" => ‘1’, "checked" => false, "leaf" => true )); array_push($bladeList, array( "text" =>‘testrt’, "status" => ‘1’, "expanded" => true, "checked" => false, "children" => $nodeList )); array_push($bladeList[0][‘children‘],$nodeList);
输出结果如下:
0: checked: false children: 0: checked: false expanded: true text: "3"
children:
//"children" => $nodeList 得到以下结构
0: checked: false leaf: true status: 0 text: "108"
//array_push($bladeList[0][‘children‘],$nodeList); 得到以下结构
1: 0: checked: false leaf: true status: 0 text: "108"
expanded: true
text: "10.0"
array_push($bladeList[0][‘children‘],$nodeList);
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。