PHP limit length of every string in array

前端 未结 3 1412
名媛妹妹
名媛妹妹 2021-01-16 20:26

I have an array with multiple strings, like this:

$str[0] = \"kasdnkjsandjabsdkjsbad\";
$str[1] = \"kasdnkjsandjasdjksabdjkasbkjdsak\";
$str[2] = \"kasdnkjsa         


        
3条回答
  •  不知归路
    2021-01-16 21:29

    you could use

    substr( $myString, $startInt, [$endInt] );
    

    to limit each string to only so many characters. An Example:

    for( $i = 0; $i < sizeof( $myArray ); $i++ ){
        $myArray[$i] = substr( $myString, 0, 20 );
    }
    

    That will limit the strings to 20 characters in length, if I did that right.

提交回复
热议问题