我决定建立一个数组来区分某些值。如果我想在数组中找到某个值,我想使用我搜索过的这个值中的其余数据:
Array
(
[0] => Array
(
[id] => 123
[0] => Array
(
[name] => Burger Joint
[pluralName] => Burger Joints
[shortName] => Burgers
)
)
[1] => Array
(
[id] => 617
[0] => Array
(
[name] => reeeJoint
[pluralName] => reeeJoints
[shortName] => reee
)
)
[2] => Array
(
[id] => 12355
[0] => Array
(
[name] => LeftJoint
[pluralName] => LeftJoints
[shortName] => Left
)
)
[4] => Array
(
[id] => 526
[0] => Array
(
[name] => asdfJoint
[pluralName] => asdfJoints
[shortName] => asdf
)
)
)
我想做某种搜索,如果有一个值123
,它只会得到一个新数组,其中包含 123 id 数组中的所有内容(在这种情况下是第一个)。
找到这个的最佳做法是什么?
谢谢!
编辑:
根据一些评论,我能够想出一种设置数组的新方法。但是我仍然想知道同样的问题,如果价值存在,用哪种方法来解决:
foreach($values as $value)
{
...
$categoriesExtract[$id] = array($category_stringArray2Sugg);
}
给了我这个数组:
Array
(
[123] => Array
(
[0] => Array
(
[name] => Burger Joint
[pluralName] => Burger Joints
[shortName] => Burgers
)
)
[617] => Array
(
[0] => Array
(
[name] => reeeJoint
[pluralName] => reeeJoints
[shortName] => reee
)
)
[12355] => Array
(
[0] => Array
(
[name] => LeftJoint
[pluralName] => LeftJoints
[shortName] => Left
)
)
[526] => Array
(
[0] => Array
(
[name] => asdfJoint
[pluralName] => asdfJoints
[shortName] => asdf
)
)
)