[英]PHP get value from key value pair
我有一個鍵值對,我想從中檢索值,並且由於它是循環的一部分,所以該鍵是動態的,因此無法通過其鍵名來調用該值。
我知道如果我有
array (size=1)
'2004-01-07 12:00' => string '12:00 pm 1:30 pm' (length=16)
如果我使用key($array)
我可以得到密鑰。 是否有類似的函數或方法來查找值? 感謝幫助!
在一個循環中,您可以定義鍵。
foreach ($array as $key => $value) {
echo $key;
echo $value;
}
如果數組中總是有1個項目-或您始終需要第一個或最后一個元素-您可以使用許多數組函數來獲取它。
例如:
reset($array) // get the value of the first element
end($array) // get the value of the last element
current($array) // get the value of the current element
// etc.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.