Like in C, can I use a string as an array?
For example:
$a = "abcd";
for ($b = 0; $b <= 3; $b++) {
echo $a[$b];
}
Is a string in PHP an array, or based on arrays as in C?
Actually yes, but you have to use another syntax:
$a = "abcd";
for ($b = 0; $b <= 3; $b++) {
echo $a{$b};
}
echo $a[$b]; works too ;)<?php
$str = "Lorem ipsum";
if (is_array($str)) {
echo "$str is array";
}
else {
echo "$str is not array";
}
?>
Result:
Lorem ipsum is not array
so....
$string[123]but also provide for$string{123}to disambiguate.