I just started using php arrays (and php in general)
I have a code like the following:
languages.php:
<?php
$lang = array(
"tagline" => "I build websites...",
"get-in-touch" => "Get in Touch!",
"about-h2" => "About me"
"about-hp" => "Hi! My name is..."
);
?>
index.php:
<div id="about">
<h2><?php echo $lang['about-h2']; ?></h2>
<p><?php echo $lang['about-p']; ?></p>
</div>
I’m using hypens (about-h2) but I’m not sure if this will cause me problems in the future. Any suggestions?
Between camel case and underscores it’s personal taste. I’d recommend using whatever convention you use for regular variable names, so you’re not left thinking “was this one underscores or camel case…?” and your successor isn’t left thinking about all the ways they could torture you for mixing styles. Choose one and stick to it across the board.
That’s why hyphens is a very bad idea – also, rarely, you’ll want to use something like
extractwhich takes an array and converts its members into regular variables:Personally, I prefer camel case, because it’s fewer characters.