Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Zend 200-710 Exam - Topic 2 Question 76 Discussion

Posted by Barney on Sep 17, 2024 at 11:24 AM

You want to access the 3rd character of a string, contained in the variable $test. Which of the following possibilites work? (Choose 2)

Suggested Answer: B, D

Get Premium 200-710 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
33 comments · newest first
MA
Marsha 11 months ago
Surprised that $test{2} still works, isn't that outdated?
CA
Carmela 12 months ago
I thought you had to start counting from 1, not 0.
CA
Catalina 12 months ago
Wait, why is $test(3) even an option? That's just wrong.
SA
Samira 1 year ago
Totally agree, those are the correct ones!
HE
Herman 1 year ago
You can use $test[2] and $test{2} for the 3rd character.
KA
Kallie 1 year ago
I’m pretty sure B and D are the right answers, but I’m a bit confused about the curly braces.
SH
Shayne 1 year ago
I feel like option A is definitely wrong, but I can't recall if D is still acceptable.
LE
Leana 1 year ago
I think I practiced something similar, but I’m not sure if using curly braces is still valid in newer PHP versions.
LE
Leslie 1 year ago
I remember that string indexing starts at 0, so the 3rd character should be at index 2.
DE
Deonna 1 year ago
Hmm, the curly brace syntax $test{3} is throwing me off. I don't think I've seen that before, so I'll skip that one and focus on the more familiar array/parentheses options.
SI
Silvana 1 year ago
I've got a good feeling about the $test[2] option. That's how I usually access individual characters in a string, so I'll go with that.
JO
Johnathon 1 year ago
Wait, is it zero-indexed or one-indexed? I'm a bit confused on that. Maybe I should try both the (2) and [2] options just to be sure.
OS
Osvaldo 1 year ago
Okay, let me see... I think the array syntax $test[2] should work, since array indices start at 0. I'll try that one.
LA
Lanie 1 year ago
Hmm, this looks like a tricky one. I'll need to think carefully about the syntax for accessing characters in a string.
CY
Cyril 2 years ago
Option B is the way to go. Accessing array elements using square brackets is the most straightforward and intuitive approach.
SH
Sheridan 2 years ago
↳ replying to Cyril
User1: Great, thanks for confirming!
MA
Matthew 2 years ago
↳ replying to Cyril
Yes, I agree. That's the correct way to access the 3rd character of a string.
MA
Marica 2 years ago
↳ replying to Cyril
I think option B) echo $test[2]; is correct.
KI
Kimberlie 2 years ago
I'm not sure about option D) echo $test{2}. I think curly braces {} are used for variables, not string characters.
RH
Rhea 2 years ago
Haha, this is a classic PHP gotcha! I remember wasting an embarrassing amount of time on this exact question during my last interview.
HI
Hildred 2 years ago
↳ replying to Rhea
D) echo $test{2};
BR
Brandon 2 years ago
↳ replying to Rhea
B) echo $test[2];
SH
Sheridan 2 years ago
I agree with Kristeen. Using square brackets [] is the correct way to access characters in a string.
AF
Afton 2 years ago
D looks like the most logical choice to me. Who uses those weird parentheses anyway? Team curly braces all the way!
GO
Goldie 2 years ago
↳ replying to Afton
I always use curly braces for accessing characters in a string. E) echo $test{3}; is the way to go.
ST
Stephaine 2 years ago
↳ replying to Afton
Actually, D) echo $test{2}; is the correct syntax for accessing the 3rd character.
MY
Myong 2 years ago
↳ replying to Afton
I agree, B) echo $test[2]; is the correct way to access the 3rd character.
BE
Belen 2 years ago
↳ replying to Afton
I think B) echo $test[2]; would work too.
KR
Kristeen 2 years ago
I think the correct options are B) echo $test[2] and E) echo $test{3}
LA
Lauran 2 years ago
I was sure that A and C were the right answers. Guess I need to brush up on my PHP string manipulation skills.
RA
Ramonita 2 years ago
B and D are the correct options. Arrays in PHP are zero-indexed, so the 3rd character is at index 2.
TE
Tegan 2 years ago
↳ replying to Ramonita
D) echo $test{2};
TE
Tegan 2 years ago
↳ replying to Ramonita
B) echo $test[2];
0/2000 characters

Save Cancel