Hey guys, here are a few tips that might help you, that in my opinion would be good to consider!
1. Use MySQLi functions instead of MySQL functions
You can use the functions procedurally or as an object, so the learning curve is very easy. A lot of the functions have very similar names. With MySQLi you can create prepared statements, you might not need them right now, but the option will be good later on. If you want to get a better head start than this, I would recommend learning PDO, but that has a hard learning curve.
http://php.net/manual/en/book.mysqli.php
2. Use descriptive camelCase $variables
A regular variable can be confusing if you read your own code later, $myvar or $item does not make much sense, unless you want to re-study your code a year later! So try to be descriptive and camelCase variables, it is a popular naming convention used in Java and Zend Framework. A variable would be something like this: $inputFileName
http://framework.zend.com/manual/en/coding-standard.naming-conventions.html
3. Master the Array’s and Multi-Dimensional Arrays
You will work with arrays a lot and they have a lot of power. When you understand how to re-arrange things and grab what you need you will see they are life-savers in many situations!
Tip: If you don’t assign a key, it will use a digit by default
// Enumerated arrays (Digits are used for the key)
$b = array ('dog', 'cat', 'fish', 10 => 255);
echo $b[0]; // Gives you dog
echo $b[255] // Gives you an error, because 255 is the value not they key!
$variable['key'] = 'value'
// Associative arrays (Words used for the key)
$c = array ('fish' => 'big', 'dog' => 'fat')
echo $c['fish'] // Gives you 'Big'
echo $c[0] // Gives you an error, the keys are associative not enumerated.
// Multi-Dimensional Array (An array that has more arrays in it)
$d = array('cat' => array(
'brown',
'yellow',
'black'),
'dog' => 'none');
echo $d['cat'][0] // Grabs 'brown'
echo $d['cat']['yellow'] // Error, yellow is the value!
echo $d['dog'] // Gives you 'none'
Some great array functions to start with:
array_pop
array_shift
array_slice
implode
explode
- and some of the sorting ones
http://php.net/manual/en/ref.array.php
4. Comment your code
You don’t have to get obsessive over it, but it might save you a lot of sweat from your forehead someday trying to figure out what you were doing. An example of a comment is with phpDoc and it looks like this:
/**
* @desc This function does nothing
*/
function Nothing()
{
return 0;
}
Alternatively you can also name all your arguments like this:
/**
* @desc This function does nothing
* @var <str> $strInput An input string that does nothing right now...
*/
function Nothing($strInput)
{
return 0;
}
This way you can write your projects documents while you program it. It takes a little effort and habit to get into, but it is going to help you someday.
5. When you are bored, practice OOP
Objects will change your programming life and make you capable of many more things. It is tricky to learn at first, and tricky to see the value at first. But after a few months of doing OOP you will be one of the happiest people alive.
Even if you don’t totally understand what you are doing, doing a little bit each day will stick in your mind and you’ll be able to recall things you’ve read about and the understanding comes together like building blocks.
http://www.php.net/manual/en/language.oop5.basic.php
6. Ask stupid questions if Google wont help you
Its easiest to ask a question where your problem rests, rather than sending a huge 300 line copy paste I noticed when you ask short and simple questions people are on it like a dog on a raw bone, they want to be the first to answer. But people tend to avoid the lengthy long questions where they must dig through a ton of code. So try to find where your error lies, and keep it simple.