Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在不使用数组的情况下获取foreach外部的值?_Php_Arrays - Fatal编程技术网

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')));