I have seen some code like below used
$row [0] ['hello'];
or like
$this->function ('abc');
Does leaving space after each string or variable is good coding practice or will it cause any problem any where ?
Only to readers. The parser does not care, except inside strings. These will yield different results:
$array = array(3);
echo "$array [0]
";
echo "$array[0]
";
Results will look something like this:
Array [0]
3
I prefer less white space over spacing things out, yet there doesnt seem to be any errors most of the time. But in my opinion, $this->function('abc');
looks nicer than $this->function ('abc');
Good coding practice is correlated with the programming language you are using. Some languages like Ruby or Python might have conflicts with leaving space in between. The syntax might be okay across all languages but I am sure that for Dynamic scripting languages it is best to practice the proper syntax to avoid bugs of any sort. It gets more complex when dealing with other formats of data. For example, JSON data. It is here that the best practice comes into play. For simple arrays it is not too important but for those complex data it will be good to use a standard for clarity sake more than anything.
I think you should use accepted standard psr-2.
From terminal you can use phpcs to check your script: phpcs --standard=PSR2 file.php