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