Sonntag, 1. Juni 2014

PHP Basics: How can I print the n-th Character of a PHP String?

// grabbing single elements out of a variable

// define the variable, in this case "NeilArmstrong"
$variable_f = "NeilArmstrong";

// write the variable using the echo command and counting to a specific character, in this case number 0 and 5
echo $variable_f[0];
echo $variable_f[5];
Wrapping this into a php file and running it will give you the following output
"Nr" since the first Character of the string is "N" and the 5th is "r"

Keine Kommentare:

Kommentar veröffentlichen