View Single Post
  #8 (permalink)  
Old 01-30-06, 08:53 PM
Patiek Patiek is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by mab
Both [] and {} work. However, if you include the {} form in a quoted string, the results are not as expected -
PHP Code:

<?php

$string 
"abcdef";
echo 
"The 1st char of the string is: $string[0]<br>";
echo 
"The 1st char of the string is: $string{0}<br>";
?>
Results in this output -
The 1st char of the string is: a
The 1st char of the string is: abcdef{0}
Or if you always use {} for strings, etc, then you don't have the problem:
PHP Code:

$string "abcdef";

echo 
"The 1st char of the string is: $string[0]<br>";
echo 
"The 1st char of the string is: {$string{0}}<br>";

// plus benefits
echo "The string is: $stringg<br>";
echo 
"The string is: {$string}g<br>";
?> 

Last edited by Patiek; 01-30-06 at 08:59 PM.