我在我的php中有一个关联数组,code.array在数组中有5个键,即Id,name,brand,store,location.The数组包含大约10000条记录。
我点击了主页上的某个链接,它传递了一些id号。如1.然后,应该在关联数组id列中搜索该id,并将相关参数推送到新数组中。或者如果有任何其他方式的.Please指南..
<html>
<head>
</head>
<body>
<a href="second.php?id=1">id</a>
</body>
</html>发布于 2014-04-16 22:18:55
你必须从它的声音中使用foreach循环。
foreach ($yourArray as $element) {
if ($element['id'] == $_GET['id']) {
// This is the element you want, feel free to do stuff
// Make sure to use this to stop looking through the array
break;
}
}发布于 2014-04-17 03:36:04
现在使用@BrandonWamboldt的解决方案。
当然,您应该将数组结构从:
[
{
id: ID,
name: NAME,
brand: BRAND,
...
},
...
]至:
{
id:
{
id: ID,
name: NAME,
brand: BRAND,
...
},
}正是因为这个原因。
https://stackoverflow.com/questions/23112049
复制相似问题