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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

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

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 :))
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

d11wtq wrote:Not sure but I think you can give it a range like $foo{2,5}
not in 5.0.4 ;)
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

Could you use:

Code: Select all

$row['variable'][0]
?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Not unless variable was a multidimensional array, not a string.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

I believe you could once upon a time, but they changed it. Dunno.
Post Reply