PHP同时获得数组值和数组的键 [英] PHP get both array value and array key

查看:139
本文介绍了PHP同时获得数组值和数组的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过阵列运行一个for循环和为阵列,其中关键是文本部分和值是URL中的每个元素创建锚元件

I want to run a for loop through an array and create anchor elements for each element in the array, where the key is the text part and the value is the URL.

我怎样才能做到这一点吗?

How can I do this please?

感谢您。

推荐答案

这应该这样做。

foreach($yourArray as $key => $value) {
    //do something with your $key and $value;
    echo '<a href="' . $value . '">' . $key . '</a>';
}

编辑:按胶囊的评论 - 改为单引号

As per Capsule's comment - changed to single quotes.

这篇关于PHP同时获得数组值和数组的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆