这似乎很容易,但我无法弄明白
$users_emails = array(
'Spence' => 'spence@someplace.com',
'Matt' => 'matt@someplace.com',
'Marc' => 'marc@someplace.com',
'Adam' => 'adam@someplace.com',
'Paul' => 'paul@someplace.com');
Run Code Online (Sandbox Code Playgroud)
我需要获取数组中的下一个元素但我无法弄清楚...例如
如果我有
$users_emails['Spence']
Run Code Online (Sandbox Code Playgroud)
我需要退回matt@someplace.com,如果是的话
$users_emails['Paul']
Run Code Online (Sandbox Code Playgroud)
我需要从顶部开始并返回spence@someplace.com
我试过这个
$next_user = (next($users_emails["Spence"]));
Run Code Online (Sandbox Code Playgroud)
这也是
($users_emails["Spence"] + 1 ) % count( $users_emails )
Run Code Online (Sandbox Code Playgroud)
但他们不回报我所期待的
reset($array);
while (list($key, $value) = each($array)) { ...
Run Code Online (Sandbox Code Playgroud)
Reset()将数组指针倒回到第一个元素,each()将当前元素键和值作为数组返回,然后移动到下一个元素.
list($key, $value) = each($array);
// is the same thing as
$key = key($array); // get the current key
$value = current($array); // get the current value
next($array); // move the internal pointer to the next element
Run Code Online (Sandbox Code Playgroud)
要导航你可以使用一个($阵列),前值($阵列),复位($数组),结束($阵列),而数据是利用电流($阵列)和/或关键($数组)读取.
或者你可以使用foreach,如果你遍历所有这些
foreach ($array as $key => $value) { ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10589 次 |
| 最近记录: |