Excuse me, what is $values[$k] and $v[$key] in this string of code $values[$k]= isset($v[$key]) ? $v[$key] : ''; What's the meaning. Sorry for the trouble, gentlemen.
Source code attached:
<?php function test($array=array(),$key='',$paixu=true){ $result=array(); foreach($array as $k => $v){ $values[$k]= isset($v[$key]) ? $v[$key] : ''; } unset($v); $paixu ? asort($values) : arsort($values); foreach ($values as $k => $v){ $result[$k] = $array[$k]; } return $result; } $data = array( array('post_id'=>1,'title'=>'如何学好PHP','reply_num'=>582), array('post_id'=>2,'title'=>'PHP数组常用函数汇总','reply_num'=>182), array('post_id'=>3,'title'=>'PHP字符串常用函数汇总','reply_num'=>982), ); $paixuhou=test($data,'reply_num',true); echo "<pre>"; print_r($paixuhou); ?>
phpcn_u1467832019-02-15 23:25:05
$values is the newly opened array in the function, $k comes from the traversal of foreach and is the array key value, $v is the array value corresponding to the key value, $key comes from the $key in the function parameter,
You can take a look at the foreach function