PHPcode $ list & quot; if (! $ Car [name]) {$ list has no information !;} Else {$ i1; foreach ($ car [name] as $ nm) {$ list... $ nm [xm] ..; $ I ++ ;}} print_r about php loop output
PHP code
$ List = ""; if (! $ Car ['name']) {$ list = 'no information! ';} Else {$ I = 1; foreach ($ car ['name'] as $ nm) {$ list. = ''. $ nm ['xm ']. ''; $ I ++ ;}} print_r ($ list );
Output data in the above code: Li Qiang, and Hong Fei
Is it possible to determine whether the results in the output data are duplicated by "Li Qiang", then the names are forcibly changed to Li Qiang 1, Li Qiang 2, Li Qiang 2, and Hong Fei?
------ Solution --------------------
Count
PHP code
$ Car ['name'] = array ('xm '=> 'Li Qiang'), array ('xm '=> 'Li Qiang '), array ('xm '=> 'Li Qiang'), array ('xm '=> 'hongfei'),); $ list = ""; if (! $ Car ['name']) {$ list = 'no information! ';} 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 );
------ Solution --------------------
PHP code
$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);