English 中文(简体)
PHP: How to pop the final items off the protocol, without actual abolition it from the range? [复制]
原标题:PHP: How to pop the last item off the array without actually removing it from the array? [duplicate]
  • 时间:2012-04-24 18:59:25
  •  标签:
  • php
  • arrays
This question already has answers here:
Closed 11 years ago.

Possible Duplicate:
PHP get index of last inserted item in array

我有阵列或多变的长度,希望能迅速而容易地了解最后一个项目在阵列中的价值(实际上不将其从阵列中删除)。 我怎么能够把最后的项目列入议程,而实际上却不将其从阵列中删除?

问题回答

Try end

<?php

$fruits = array( apple ,  banana ,  cranberry );
echo end($fruits); // cranberry

?>

For numeric (non-associative) zero-based array you can use this:

$arr = array( one ,  two ,  three ,  four ,  five );
print $arr[count($arr)-1];  //  five 

Use array end So if I have an array:

$array_example = array( one ,  two ,  three );

我要谈最后一个项目,我可以这样做:

echo end($array_example);

这将反映阵列的最后部分,但不会影响阵列。

在这样做之后,如果你想要重新确定阵列中第一个项目的内部阵列点(以便你能够继续正常工作),那么就重新确定阵列点:

reset($array_example);

最后一期=1美元

this is an alternative to using end, so that you don t have the consequence of having the array s internal pointer moved to the end of the array end - php.net





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签