Welcome! Log In Create A New Profile

Advanced

functions - scope

Posted by Mac 
Announcements Last Post
Announcement : Programming Students at UNISA School of Computing 06/19/2019 02:01PM
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
avatar
Mac
functions - scope
July 24, 2013 11:23AM
Say I had a function x that takes an argument

Language: PHP
function x($arg) { ..whatever }

Anything you want to do with $arg, do it inside the function. For example, do not clean $arg outside the function, then send it to the function. Clean it inside.
avatar Re: functions - scope
July 24, 2013 12:11PM
Yes noted!!! thumbs uphere's my example:

Language: PHP
<?php function x ($arg1, $arg2){ echo "Hi, my name is ".$arg1." and I specialize in ".$arg2." web application development"; } $yourName = "Sipho"; $yourLang = "php";   x($yourName, $yourLang); ?>
avatar
Mac
Re: functions - scope
July 24, 2013 12:48PM
To be clearer...

Language: PHP
function x($arg) { $arg=str_replace("these words", "with these words", $arg); //do something with $arg }

The str_replace function is thus used inside the function.

Not like this.

Language: PHP
$arg=str_replace("these words", "with these words", $arg);   function x($arg) { //do something with $arg }
avatar Re: functions - scope
July 24, 2013 01:33PM
You've mentioned a very useful function here Prof MAC smile, I quickly see how much time it will save me in the future in arrays, forms etc..

Let me roll up my sleeves and see what more this function is capable of.. Am definitely throwing it into my beg of tricks!!!!smoking smiley
Re: functions - scope
July 25, 2013 05:06PM
Makes a lot of sense, limiting the scope of variables also saves us having to come up with different names for variables that hold similar information.
Re: functions - scope
September 09, 2013 04:10PM
Sorry, only registered users may post in this forum.

Click here to login