9

Does it matter whether an uppercase or lower case a is used for php arrays?

For example: array() vs. Array()

2
  • 6
    I had that question once. Took about a minute to test. Commented Jul 13, 2010 at 9:39
  • @ManosDilaverakis For sure, it is about standards and not testing. New PHP versions bring changes and thus such a question is absolutely justified. The PHP docs state array() not Array(). @David: If you are not sure, simply use $newarray = []; Commented Sep 27, 2017 at 12:21

4 Answers 4

11

I believe the OP is referring to this:

<?php
$arr = array("foo" => "bar", 12 => true);
var_dump($arr);
// returns array(2) { ["foo"]=>  string(3) "bar" [12]=>  bool(true) }

$arr = Array("foo" => "bar", 12 => true);
var_dump($arr);
// also returns array(2) { ["foo"]=>  string(3) "bar" [12]=>  bool(true) }
?>

So the answer is no, there is no difference

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

Comments

3

If you mean:

$array = Array(1,2,3);

vs

$array = array(1,2,3);

vs

$array = aRRaY(1,2,3);

there is no functional difference. It is only a question of style. Like PHP functions, the array language construct is case-insensitive.

Comments

2

If you mean array names/variables, then yes it does, PHP variables are case-sensitive. If however, you are asking about standards, have a look at:

PHP Coding Standard about Naming Conventions

3 Comments

Also, array keys are case sensitive if you use strings not numbers. They are normal strings and compared as strings.
I dont think the OP is asking about variables - i think he is referring to the use of the word "Array" or "array"
@seengee: yeah that might be it
0

David - yes it does. they are treated as different variables $varPerson and $varperson.

However, the main thing really is more that you should be following some kind of coding guideline doc that mandates case and scope of all variables. this is probably a much more important driver of variable naming/case than the simple question implies.

jim

Comments

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.