PHP数组合并,如何构建长尾?
- 内容介绍
- 文章标签
- 相关推荐
本文共计329个文字,预计阅读时间需要2分钟。
自定义函数.php中,变量$i和$j的使用如下:
php$i; $j--;if ($i==$j) { // 如果该兼职的一维数组已合并过,则跳过 if (in_array($i, $key_arr)) { continue; } // 如果两个兼职的with1和with2属性相等,则记录要合并的 if ($array[$i]['with1']==$array[$j]['with1'] && $array[$i]['with2']==$array[$j]['with2']) { // 记录要合并的兼职 }}
$i; $j--) { //如果该兼职的一维数组已经合并过 则跳过 if(in_array($i, $key_arr)){ continue; } if( $array[$i]['with1'] == $array[$j]['with1'] && $array[$i]['with2'] == $array[$j]['with2'] ){ //记录要合并的一维数组的键值 $key_arr[$n] = $j; $n++; $array[$i]['id_quantity']++; $array[$i]['id_stock_detail'] .= ','.$array[$j]['id_stock_detail']; } } } //释放掉合并过的一维数组 foreach ($key_arr as $value) { unset($array[$value]); } return $array; } /** *通过with 对数组排序 ,$order 为排序标准 SORT_DESC 降序;SORT_ASC 升序 *@Author Toby *@DateTime 2017-09-01 *@param [type] $array *@param [type] $with *@param [type] $order *@return [type] */ function arraysort($array,$with,$order) { $sort = array( 'direction' => $order, //排序顺序标志 'field' => $with, //排序字段 ); $arrSort = array(); foreach($array AS $uniqid => $row){ foreach($row AS $key=>$value){ $arrSort[$key][$uniqid] = $value; } } if($sort['direction']){ array_multisort($arrSort[$sort['field']], constant($sort['direction']), $array); } return $array; }
本文共计329个文字,预计阅读时间需要2分钟。
自定义函数.php中,变量$i和$j的使用如下:
php$i; $j--;if ($i==$j) { // 如果该兼职的一维数组已合并过,则跳过 if (in_array($i, $key_arr)) { continue; } // 如果两个兼职的with1和with2属性相等,则记录要合并的 if ($array[$i]['with1']==$array[$j]['with1'] && $array[$i]['with2']==$array[$j]['with2']) { // 记录要合并的兼职 }}
$i; $j--) { //如果该兼职的一维数组已经合并过 则跳过 if(in_array($i, $key_arr)){ continue; } if( $array[$i]['with1'] == $array[$j]['with1'] && $array[$i]['with2'] == $array[$j]['with2'] ){ //记录要合并的一维数组的键值 $key_arr[$n] = $j; $n++; $array[$i]['id_quantity']++; $array[$i]['id_stock_detail'] .= ','.$array[$j]['id_stock_detail']; } } } //释放掉合并过的一维数组 foreach ($key_arr as $value) { unset($array[$value]); } return $array; } /** *通过with 对数组排序 ,$order 为排序标准 SORT_DESC 降序;SORT_ASC 升序 *@Author Toby *@DateTime 2017-09-01 *@param [type] $array *@param [type] $with *@param [type] $order *@return [type] */ function arraysort($array,$with,$order) { $sort = array( 'direction' => $order, //排序顺序标志 'field' => $with, //排序字段 ); $arrSort = array(); foreach($array AS $uniqid => $row){ foreach($row AS $key=>$value){ $arrSort[$key][$uniqid] = $value; } } if($sort['direction']){ array_multisort($arrSort[$sort['field']], constant($sort['direction']), $array); } return $array; }

