0
我的输出是这样的:如何从多个数组中获取in_array值?
Array (
[0] => Array (
[type] => 1
[position] => main-widgets
[key_position] => 3
[code] => template/portfolio.inc
)
[1] => Array (
[type] => 2
[position] => main-widgets
[key_position] => 3
[code] => This is a code
)
)`
我怎么能如果in_array(Array[position]=='main-header'
不使用foreach
检查?
这是我的代码:
if(in_array('main-header', array_column($PAGE['templates'], 'position'))) {
$count = array_count_values($PAGE['templates']['position']);
if($count['main-header']>1){
echo 'multiple';
foreach($PAGE['templates'] as $pos){
if($pos['type'] == 1){
require $base['basepath'].$pos['code'];
}else {
echo $pos['code'];
}
}
} else {
echo 'Only 1';
if($PAGE['templates']['type'] == 1){
require $base['basepath'].$PAGE['templates']['code'];
}else {
echo $PAGE['templates']['code'];
}
}
}
我的PHP版本是5.4.35 – DecoderNT 2015-02-24 21:35:32
确定从https://github.com/ramsey/ar下载了该类ray_column/blob/master/src/array_column.php – DecoderNT 2015-02-24 21:36:52
增加了另一个选项。 – AbraCadaver 2015-02-24 21:45:51