如何将同一数组中的一个键值与其他键值进行匹配?
我很抱歉,因为我知道这可能是一个菜鸟问题,但我有太多的工作要做,所以我无法完成我的 PHP 学习过程。
假设我有一个用于文件扩展名的变量和一个 PHP 数组,如下所示:
$fileExt = ".php";
$mainNav = array(
"page01" => array (
"id" => "value",
"name" => "value",
"title" => "value",
"url" => need same "id" value + $fileExt
),
"page02" => array (
"id" => "value",
"name" => "value",
"title" => "value",
"url" => need same "id" value + $fileExt
),
);
但我喜欢这样,而不是对“url”的值进行硬编码,它与键“name”的值+我已经存在的文件扩展名相匹配有一个变量,以防万一我以后需要更改它。
I'm sorry because i know that is probably a noob question, but i have so much work to do that i cant finish my PHP learning process.
Let's say i have a variable for the file extension and an array in PHP like that:
$fileExt = ".php";
$mainNav = array(
"page01" => array (
"id" => "value",
"name" => "value",
"title" => "value",
"url" => need same "id" value + $fileExt
),
"page02" => array (
"id" => "value",
"name" => "value",
"title" => "value",
"url" => need same "id" value + $fileExt
),
);
But I like that instead of hard coding the value for "url", it match the value of the key "name" + the file extension that i already have in a variable just in case i need to change it later.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这应该可以完成这项工作:
This should do the job:
有几种方法可以实现此目的,下面可能是最简单的方法,无需查看您正在使用的所有代码。
我也在想这些东西是存储在数据库中的吗?如果是这样,只需为 url 添加一个字段,当您插入页面时,请同时执行 url 操作。
There's a few ways to accomplish this, below is probably the easiest without seeing all the code you are using.
I'm also thinking that this stuff is being stored in a database? If so just add a field for the url and when you insert the page go ahead and do the url at the same time.