PHP 在多维/嵌套数组中查找值
我已经在网站和网络上进行了搜索,并尝试了各种递归函数等,但都无济于事,所以我希望这里有人能指出我哪里出错了:)
我有一个名为 $meetingArray 具有以下值;
Array (
[0] => Array (
[Meet_ID] => 9313
[Meet_Name] => 456136
[Meet_CallInNumber] =>
[Meet_AttendeeCode] =>
[Meet_Password] =>
[Meet_ScheduledDateTime] => 2011-07-18 16:00:00
[Meet_ModeratorCode] =>
[Meet_RequireRegistration] => 0
[Meet_CurrentUsers] => 0
)
[1] => Array (
[Meet_ID] => 9314
[Meet_Name] => 456120
[Meet_CallInNumber] =>
[Meet_AttendeeCode] =>
[Meet_Password] =>
[Meet_ScheduledDateTime] => 2011-07-18 16:00:00
[Meet_ModeratorCode] =>
[Meet_RequireRegistration] => 0
[Meet_CurrentUsers] => 0
)
)
我还有一个名为 $meetID
的变量。
我想知道 $meetID
中的值是否出现在数组中的 [Meet_Name]
中,并简单地评估这个 true 或 false。
在我开枪自杀之前,非常感谢任何帮助:)
I've trawled the site and the net and have tried various recursive functions etc to no avail, so I'm hoping someone here can point out where I'm going wrong :)
I have an array named $meetingArray
with the following values;
Array (
[0] => Array (
[Meet_ID] => 9313
[Meet_Name] => 456136
[Meet_CallInNumber] =>
[Meet_AttendeeCode] =>
[Meet_Password] =>
[Meet_ScheduledDateTime] => 2011-07-18 16:00:00
[Meet_ModeratorCode] =>
[Meet_RequireRegistration] => 0
[Meet_CurrentUsers] => 0
)
[1] => Array (
[Meet_ID] => 9314
[Meet_Name] => 456120
[Meet_CallInNumber] =>
[Meet_AttendeeCode] =>
[Meet_Password] =>
[Meet_ScheduledDateTime] => 2011-07-18 16:00:00
[Meet_ModeratorCode] =>
[Meet_RequireRegistration] => 0
[Meet_CurrentUsers] => 0
)
)
I also have a variable named $meetID
.
I want to know if the value in $meetID
appears in [Meet_Name]
within the array and simply evaluate this true or false.
Any help very much appreciated before I shoot myself :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定你的意思
,但只需将
$h[$key]==$needle
条件替换为满足您需求的内容即可。I am unsure what you mean by
but simply substitute the
$h[$key]==$needle
condition with something that meets your needs.对于一维数组,您可以使用
array_search()
。这可以适用于多维数组,如下所示:For single-dimensional arrays you can use
array_search()
. This can be adapted for multi-dimensional arrays like so:编写一个类似这样的方法:
如果在数组中找到记录,此函数将评估 true,并且还使您能够快速访问与该 ID 匹配的特定嵌套数组。
Write a method something like this:
This function will evaluate true if the record is found in the array and also enable you to quickly access the specific nested array matching that ID.