What is the situation !!! For example: $ str = "abcadef"; $ strone = $ str [0]; for ($ I = 0; $ I & lt; strlen ($ str ); $ I ++) {if ($ strone = $ str [$ I]) {$ str [$ I] = ""; what is the situation !!!
For example:
$ Str = "abcadef ";
$ Strone = $ str [0];
For ($ I = 0; $ I If ($ strone = $ str [$ I]) {
$ Str [$ I] = "";
}
}
Var_dump ($ str );
Displayed:
String (7) "bcdef ";
Excuse me, why is this string still 7 characters long? is there any way to change it to 5 characters long,
------ Solution --------------------
$str="abcadef";
$strone=$str[0];
$r = '';
for($i=0;$i
if($strone != $str[$i]){
$r .= $str[$i];
}
}
$str = $r;
var_dump($str);
------ Solution --------------------
The solution has been mentioned above, but to avoid repeating the same mistakes, let's talk about the theory --
The program looks "reasonable", but it is actually incorrect. The key lies in the way the php core stores variables.
Php records the length after assigning values to a string variable. to change the length, you need to assign a value again.
$ Str [x] = ''. you cannot assign a new value to the string variable because'' is a null byte and can only be used as a null string.
It is feasible to replace a non-null byte.
For more information, see php kernel.