php - Problems with array Statement -
hello friends problem statement 2 string
$i=0; $arr['lam'] = preg_replace('/\s+/', 'd', $arr['lam']); print_r($arr); ///array ( [id] => 123 [lam] => d ) echo '_'.$arr['lam'].'_'; ///_d_ if($arr['lam']!='d'){ $i++; } echo $i; //1
why $i==1?
this works expected:
<?php $i=0; $arr = array('id' => 123, 'lam' => ' '); $arr['lam'] = preg_replace('/\s+/', 'd', $arr['lam']); print_r($arr); // array ( [id] => 123 [lam] => d ) echo '_'.$arr['lam'].'_'; // _d_ if($arr['lam'] != 'd'){ $i++; } echo $i; // 0 ?>
keep in mind regex /\s+/
replace white-space characters. may possible 'd', while 'd', contains other content. don't know goal code, looks should improve regular expression based on input.
Comments
Post a Comment