php - string length not decremented when unset string index -


i trying create palindrome deleting 1 character string @ time . while unsetting string index .the string length not getting reduced.

$s = "arun"; var_dump ($s); $s[1] = null; var_dump($s) ; 

output

string(4) "arun" string(4) "aun" 

why length not reduced.

because not in way reducing string, replacing 1 character.

your string gets transformed a r u n a (null) u n, still 4 chars long.

to achieve goal, use substr_replace

<?php $s = "arun"; var_dump ($s); //arun $s = substr_replace($s, "", 1,1); var_dump($s); //aun 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -