2

Given an array of $a = array("Hello","World") and $a[0] holds Hello and $a[0][0] holds value H, is it correct to say that $a is a "Multidimensional String Array"?

1
  • And $a[0][0][0][0][0] is still H. And $a[0]['foo']['bar'] is still H (on < 5.4). Just because it looks like an array, doesn't mean it is one... Commented Apr 1, 2012 at 14:32

2 Answers 2

10

No, $a is a 1-dimensional array. Period.

Although strings can be accessed/modified by character using index notation, and are implemented internally as character sequences, PHP strings are not true PHP arrays.

Sign up to request clarification or add additional context in comments.

1 Comment

it has been called substring access in the past.
5

Is it correct to say that $a is now a Multidimensional String Array?

Ask your PHP:

foreach($a[0] as $char);

and see what does it say.

1 Comment

Invalid argument supplied for foreach(), so it's not an array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.