21,886
社区成员
发帖
与我相关
我的任务
分享
Array ( [0] => Array ( [class_id] => 1101 [resource_author] => 1 [resource_status] => 6 ) [1] => Array ( [class_id] => 1103 [resource_type] => [resource_author] => 2 [resource_status] => 5 ) [2] => Array ( [class_id] => 1103 [resource_author] => 2 [resource_status] => 5 ) [3] => Array ( [class_id] => 1103 [resource_author] => 5 [resource_status] => 6 ) [4] => Array ( [class_id] => 1103 [resource_type] => [resource_author] => 5 [resource_status] => 6 ) )
$arr = Array( '0' => Array ( 'class_id' => 1101 , 'resource_author' => 1 , 'resource_status' => 6 ) , '1' => Array ( 'class_id' => 1103 , 'resource_type' => '' , 'resource_author' => 2 , 'resource_status' => 5 ) , '2' => Array ( 'class_id' => 1103 , 'resource_author' => 2 , 'resource_status' => 5 ) , '3' => Array ( 'class_id' => 1103 , 'resource_author' => 5 , 'resource_status' => 6 ) , '4' => Array ( 'class_id' => 1103 , 'resource_type' => '' , 'resource_author' => 5 , 'resource_status' => 6 ) );
$out = array();
foreach($arr as $v){
if(array_key_exists('resource_author',$v) && !in_array($v['resource_author'],$out)){
$out[] = $v['resource_author'];
}
}
print_r($out);
$arr = array ( array ( 'class_id' => 1101, 'resource_author' => 1, 'resource_status' => 6 ),
array ( 'class_id' => 1103, 'resource_type' =>'', 'resource_author' => 2, 'resource_status' => 5 ),
array ( 'class_id' => 1103, 'resource_author' => 2, 'resource_status' => 5 ),
array ( 'class_id' => 1103, 'resource_author' => 5, 'resource_status' => 6 ),
array ( 'class_id' => 1103, 'resource_type' =>'', 'resource_author' => 5, 'resource_status' => 6 ) );
$newArr = array();
foreach($arr as $value){ //遍历第一层数组
$author = $value['resource_author']; //获取到需要重新组成数组的值
if(!in_array($author,$newArr)){ //判断该值是否已经存在新数组中
array_push($newArr,$author); //不存在则加入该新数组中
}
}
print_r($newArr);
$arr = Array ( [0] => Array ( [class_id] => 1101 [resource_author] => 1 [resource_status] => 6 ) [1] => Array ( [class_id] => 1103 [resource_type] => [resource_author] => 2 [resource_status] => 5 ) [2] => Array ( [class_id] => 1103 [resource_author] => 2 [resource_status] => 5 ) [3] => Array ( [class_id] => 1103 [resource_author] => 5 [resource_status] => 6 ) [4] => Array ( [class_id] => 1103 [resource_type] => [resource_author] => 5 [resource_status] => 6 ) );
$newArr = array();
foreach($arr as $value){ //遍历第一层数组
foreach($value as $resource){ //遍历第二层数组
$author = $resource['resource_author']; //获取到需要重新组成数组的值
if(!in_array($author,$newArr)){ //判断该值是否已经存在新数组中
array_push($newArr,$author); //不存在则加入该新数组中
}
}
}
print_r($newArr);
$arr1=array();