抓取foreach中数组值的序号(Grab ordinal number of the array value inside foreach)

编程入门 行业动态 更新时间:2024-10-27 14:26:18
抓取foreach中数组值的序号(Grab ordinal number of the array value inside foreach)

你好,

我想在foreach循环中获取数组键的序号。

<?php $array = array("id" => 2, "username" => "foobar"); foreach($array as $value){ $array_key = search_array($value, $array); //find the ordinal number of $array_key from $array here. echo $value; }

count返回数组中数组键的全部数量,我需要获取数组键的序号。 我希望你们明白我的要求。

Hello,

I want to grab the ordinal number of an array key inside a foreach loop.

Example

<?php $array = array("id" => 2, "username" => "foobar"); foreach($array as $value){ $array_key = search_array($value, $array); //find the ordinal number of $array_key from $array here. echo $value; }

count returns the entire number of array keys in the array, i need to grab the ordinal number of the array key. I hope you guys understand what i ask.

更多推荐

本文发布于:2023-08-05 13:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1432709.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   序号   foreach   Grab   array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!