Jump to content

Help Whit Basic Questions For The Novice


ICIT

Recommended Posts

I’ve never programmed before and my first contact with that area was HTML and CSS (if you could call it programming) and the next step is PHP (I read the JavaScript tutorial first) and I find W3Schools very useful and, from a raw beginners point of view, sometimes lacking the real basics of the subject in question; and sometimes missing to explain newly introduced code.To make it specific here are two examples from where I’m reading just now:

  1. I'm missing a list of terminology. This is quite general as I’ve been reading so far, but here are some examples of terms often used in PHP (and JavaScript) I recently encountered that I like to have an exact and thorough definition of: Declaration: http://www.w3schools...p_variables.asp (it is understandable but could be better) Function: http://www.w3schools.../php_string.asp Statement: http://www.w3schools...php_if_else.asp There are of course a lot of more examples. If the list could not be provided at W3Schools it would be fine with a reference to a list somewhere (I’ve looked quite a lot all over the web and at places such as php.net, etc., without finding any satisfying).
  2. Code without explanation. http://www.w3schools.../php_arrays.asp The paragraphs of Associative and Multidimensional Arrays: The “=>” comes in to use. But is not explained at all. In this particular example I’d like to know the name of it, and the rules for when and where it should be used. Another example is found in the JavaScript tutorial: It’s about cookies in the Advanced chapter: http://www.w3schools.../js_cookies.asp A great deal of the code that comes in use here has never been used ore explained earlier in the JavaScript tutorial so when I got there it became just too much so I stopped and haven’t continued since then (but I hope to do as soon as I’ve find a way that could get through that jungle). I really would appreciate some information or hint of where to find out more about what is going on in that chapter. I don’t think I’m alone cherishing that hope.

Link to comment
Share on other sites

a function basically does something for you, and most of the time it fetches a value too.there are functions which are built into PHP, and functions which coders code themselves. a function basically has 3 things associated with it: - the name of the function - the data which you send to the function (called parameters or arguments) - the data which is received from the function (called returns) here's the strlen() function on the PHP manual: http://php.net/manual/en/function.strlen.php the description says "Returns the length of the given string.".and above the description text, is the function's syntax:

int strlen ( string $string )

the word just before the opening round bracket ( is the function's name, so strlen in this case.the words inside the ( ) brackets are the parameters.the words before the function name are the returns. each parameter will show 2 things.the data type of the parameter, string in this case.an example variable name for the parameter, $string in this case. this is mainly used to give a very short description for the parameter. each return will show 1 thing.the data type of the return, int in this case. so as some example code:

$test = 'testing 123'; // declare a variable called $test$length = strlen( $test ); // send 'testing 123' to the strlen function, and store it's return value into a variable called $lengthecho $length; // this will output 11

more info about functions on the PHP manual: http://php.net/manual/en/language.functions.php An array consists of 0 or more elements.Each element has 2 things, a key and a value. for example, if we has an array consisting of the days of the week:

$days = array(0 => 'Monday',1 => 'Tuesday',2 => 'Wednesday',3 => 'Thursday',4 => 'Friday',5 => 'Saturday',6 => 'Sunday');

this array has 7 elements.the key is before the =>the value is after the => you could say, the $days array has integer keys ranging from 0 to 6. the above array is actually the same as:

$days = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');

where you only specify the values, and the keys are automatically set to integers starting from 0, and increasing by 1 for the next value. echo $days[2]; will output Wednesday in both those 2 examples. so when creating an array, the => operator is really only useful for when you don't want to use the "automatic integer keys", such as if you wanted to use string keys (also called dictionary keys).eg.

$dayWeathers = array('Monday' => 'Sun','Tuesday' => 'Rain','Wednesday' => 'Storm','Thursday' => 'Rain','Friday' => 'Storm','Saturday' => 'Hurricane','Sunday' => 'Sun');

so in that exampe, the array keys are now the day names, and the array values are the weathers. echo $dayWeathers['Sunday']; will output Sun. The => operator is also used when looping around all elements of an array, and you want to use the key of each element inside the loop.

foreach ($dayWeathers as $dayName => $dayWeather) {    echo 'The weather on '.$dayName.' will be '.$dayWeather.'!<br />';}

Which will output:The weather on Monday will be Sun!The weather on Tuesday will be Rain!etc more info on arrays: http://php.net/manual/en/language.types.array.php You might find this helpful for js cookies: http://w3schools.invisionzone.com/index.php?showtopic=40006 When something has been declared, it means it has been created.

$someVariable = 'some string';

that declares/creates a variable called $someVariable and set's the variable's value to 'some string'. more info on php variables: http://php.net/manual/en/language.variables.php also more info about php if statements here: http://www.php.net/manual/en/control-structures.if.php the php manual is the best place to keep looking back to, the more you familiarize yourself with it, the easier coding php will become.

Link to comment
Share on other sites

Thanks a lot JamesB!Really appreciate the comprehensive answers and included links! :good:Some parts of it put new questions (two).I'll see if I can find the answers to them at php.net.If I shouldn't succeed I'll hope I can come back here again.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...