Page 1 of 1

Can anyone explain: $row['variable']{0}

Posted: Sun Oct 09, 2005 9:49 am
by mikebr
I have come accross the following which I think means the first char of the returned value:

Code: Select all

if ($row['variable']{0}!='+') {
// We DO NOT have an + as the first char of the string
} else {
// We have an + as the first char of the string
}
Can someone just confirm this?

Thanks

Posted: Sun Oct 09, 2005 10:30 am
by Chris Corbyn
It does yes. Strings are treated like arrays. That's the way to get that character from the "array". Not sure but I think you can give it a range like $foo{2,5} (Although that's what substring does anyway :))

Posted: Sun Oct 09, 2005 11:22 am
by feyd
d11wtq wrote:Not sure but I think you can give it a range like $foo{2,5}
not in 5.0.4 ;)

Posted: Sun Oct 09, 2005 11:34 am
by pilau
Could you use:

Code: Select all

$row['variable'][0]
?

Posted: Sun Oct 09, 2005 12:16 pm
by d3ad1ysp0rk
Not unless variable was a multidimensional array, not a string.

Posted: Sun Oct 09, 2005 6:03 pm
by Skara
I believe you could once upon a time, but they changed it. Dunno.