0
我想从$ max中检索数组中的最后一个元素,并在数组$ set_of_path中引用它。我只想要最后一个值。这个代码的问题是这个$ max值谁输出值0到文件结尾,从而不是输出最后一个值..每个元素都实现了..有人可以帮助我。提前致谢。从循环中获取最后一个数字以将其引用为数组中的索引
for($ind=0;$ind <count($array_file[0]['pair']);$ind++) {
....
...
if((($city)===$initial or ($city[0]===$initial))){
$x =$array_file[0]['pair'][$ind]['city'];//display all cities
if ((end($x))===$final){
//push $array_file content into the array
$xd[]=$array_file[0]['pair'][$ind];
$count=count(end($xd));
$last_element = array();
$a[] = array_merge($xd);
$end = count(end($a));
$push = array_push($last_element,$end);
$max = max($last_element)-1;
print_r($max);
[email protected]$a[$max];
print_r($set_of_path);
print_r('<pre>');
}
};
...
...
.
...
.
..
我尝试的sizeof但每个循环递增时间,值被更新和输出1 2 3 4 ...环路休息后..所以,尺寸的效率不高:/ – 2012-02-03 16:20:25
在循环外创建一个变量,并在循环内部只增加数字,或者通过每次迭代执行sizeof以更新循环外部的变量。 – 2012-02-03 16:21:55
非常感谢你,我看到了我的错误..上帝保佑你 – 2012-02-04 15:13:46