Php 如何在不使用数组的情况下获取foreach外部的值?
我想在不使用数组的情况下获取Php 如何在不使用数组的情况下获取foreach外部的值?,php,arrays,Php,Arrays,我想在不使用数组的情况下获取calleridnum。这可能吗? 还是有其他方法可以做到这一点 我有以下代码: $participants = [ [ 'calleridnum' => 1, 'test' => 'yay' ], [ 'calleridnum' => 2, 'test' => 'yay' ], [ 'calleridnum' => 3, 'test
calleridnum
。这可能吗?
还是有其他方法可以做到这一点
我有以下代码:
$participants = [
[ 'calleridnum' => 1,
'test' => 'yay'
],
[ 'calleridnum' => 2,
'test' => 'yay'
],
[ 'calleridnum' => 3,
'test' => 'yay'
]
];
$conferance_participants = [
[ 'uid' => 1,
'test' => 'yay2',
'dit' => 'deze'
],
[ 'uid' => 2,
'test' => 'test',
'dit' => 'wew'
]
];
foreach ($participants as $key=>$p) {
foreach ($conferance_participants as $key=>$cp) {
if ($p['calleridnum'] == $cp['uid']) {
$calleridnum[] = $p['calleridnum'];
}
}
}
print_r( $calleridnum );
我的输出是:
Array ( [0] => 1 [1] => 2 )
但我希望输出是这样的
1,2
尝试以下操作:
内爆
将数组转换为字符串
$calleridnum= [];
foreach ($participants as $key=>$p) {
foreach ($conferance_participants as $key=>$cp) {
if ($p['calleridnum'] == $cp['uid']) {
$calleridnum[] = $p['calleridnum'];
}
}
}
$result = implode(',', $calleridnum);
echo $result;
使用内爆()
echo $str = implode (",", $calleridnum);
我将简单地使用,以及as
如果$calleridnum==1,那么我可以不使用foreach-like检查每个值吗如果$calleridnum==1,那么应该是真的,因为值是1,2?你可以简单地在数组中使用而不是使用foreach-like如果$calleridnum==1,那么我可以不使用foreach-like检查每个值吗,$calleridnum))
您是否在比较$participants
和$conference\u participants
中的数据?
echo implode(',', array_intersect(array_column($conferance_participants,'uid'), array_column($participants,'calleridnum')));