Go ahead ...
1, string
string concatenation, string is no + this operator, so is:
$a = ' Hello '; $a . = ' World '; Echo $a ; # back to Hello world
$a = ' Hello '; $b $a . ' World '; Echo $b ; # result "HelloWorld
To manipulate a string, it is operated by subscript.
1<?PHP2 //gets the first character of a string3 $str= ' This is a test. ';4 $first=$str[0];5 6 //gets the third character of a string7 $third=$str[2];8 9 //gets the last character of the stringTen $str= ' This is still a test. '; One $last=$str[strlen($str)-1]; A - //Modify the last character of a string - $str= ' Look at the sea '; the $str[strlen($str)-1] = ' E '; - -?>
2. Array
Now you can define it directly through [] and it feels good.
$a = [
' Foot ': ' H ',
]
Delete a data
unset ($a [' foot ']);
However, the index of key is not re-established after deletion, and the code is attached:
<? PHP $a Array (1 = ' one ', 2 = ' one ', 3 = ' three '); unset ($a[2]); /* Would produce an array that would has been defined as $a = array (1 = ' one ', 3 = ' three '); And not $a = array (1 = ' one ', 2 = ' three '); */
Delete all data:
foreach ($aas$i$value): unset($a [$i]);
Print an array
Print_r ($a);
To calculate the size of an array:
$count Count ($array);
If you want to reassign value, you can do so by referencing it in the loop:
But this kind of no-brain change should seldom be used;
$arr = [' a ' = = ' B ']; foreach ($arr as$key=>&$value) { $value= ' Test ';}
Add an official example:
<? PHP foreach (array as &$value) { $value$value * 2 ;}? >
Learn PHP record "three"