时间:2021-07-01 10:21:17 帮助过:4人阅读
$list=""; if(!$car['name']){ $list= '没有任何信息!'; }else{ $i=1; foreach($car['name'] as $nm){ $list.=' '.$nm['xm'].' '; $i++; } } print_r($list);
$car['name'] = array( array('xm' => '李强'), array('xm' => '李强'), array('xm' => '李强'), array('xm' => '鸿飞'), ); $list=""; if(!$car['name']){ $list= '没有任何信息!'; }else{ $i=1; $buf = array(); foreach($car['name'] as $nm){ if(! isset($buf[$nm['xm']])) $buf[$nm['xm']] = ''; $list .= "\n" . $nm['xm'] . ($buf[$nm['xm']]++) . "\n"; $i++; } } print_r($list);
------解决方案--------------------
$list=""; $car = array('name'=>array(0=>array('xm'=>'liming'),1=>array('xm'=>'bill'), 2=>array('xm'=>'bill'), 3=>array('xm'=>'bill'))); if(!$car['name']){ $list='Nothing'; }else{ $i = 1; foreach($car['name'] as $nm) { if(strstr($list,$nm['xm']) && $i == 1) { $list = str_replace($nm['xm'],$nm['xm'].$i,$list); $list .= $nm['xm'].($i+1); $i++; }else{ if(strstr($list,$nm['xm'])) { $list .= $nm['xm'].($i+1); $i++; }else{ $list .= $nm['xm']; } } } } print_r($list);