The way it's used now is
It seems foolish to do so. What is the simple wording?
Reply content:
I have another idea: since what you want is to do something else at the end of the day, that is to do something special.
Then I think that the last element should not be placed in the original array list, but should be extracted separately, so the following method:
$last = Array_pop ($list);
foreach ($list as $v) Do_common ($v);
Special action
Do_special ($last); use End ($array) directly to take the last value, you can use the PHP pointer function
/*** Created by Phpstorm.* User:huage.org* date:2014-09-06* time:13:43 */$array 1=Array(1,2,3,4);$array 2=Array("Lin Chi-ling","Liu Tao","Sui and Tang","Athena Chu");$array 3=Array("Liu Tao",2,"Athena Chu",1,"Lin Chi-ling");Echo End($array 1);//To point the inner pointer of the array to the last cell, for all arraysEcho "
";Echo End($array 2);Echo "
";Echo End($array 3);
$list = Array (' A ', ' B ', ' C ');
foreach ($list as $k = = $v) {
if ($v! = End ($list)) {
Not the last one.
} else {
The last one
}
Putting count ($list) out of the loop can improve efficiency. Are you sure you can do this?
$i start from 0, Count ($list) is 1 larger than $i, do you think it will output "last"? $i initial value equals 1.
A bit of advice on your code should improve efficiency.
Assign count ($list) to another value, such as: $len, put this outside the loop. The condition is judged as if ($i! = $len).
You can judge by this:
$len = count ($list);
$lastVal = End ($list);
if ($lastVal = = $list [$len-1]) {
Echo ' last ';
}
?> $count = count ($result)-1;
foreach ($result as $key = = $v) {
if (empty ($v)) continue;
$sql. = "('";
$sql. = Implode ("', '", $v);
$sql. = "')";
if ($key < $ $count) {
$sql. = ",";
}
}1 array values are not repeated $val ==end ($array)
2 1 Floor said to change the idea of processing
3 sense code is relatively concise
$fruit = Array (' a ' = = ' Apple ', ' b ' = ' banana ', ' c ' = ' cranberry ');
Reset ($fruit);
while (list ($key, $val) = each ($fruit)) {
echo "$key = $val \ n";
if (!current ($fruit)) echo ' last ';
}
It's a question of high efficiency.