Re: [PHP][Tutorial]Functions
It looks good.
Quote:
Originally Posted by
Dj.flames
This was not even helpfull.
could have made it noob friendly,
i already know this i will be making a better tutorial with screenies on what it turns out to be,
and how to make a program
Something's telling me you don't know shit about what you're talking about.
Re: [PHP][Tutorial]Functions
yeaa preet easyyy :P:P:P
nice tut still
Re: [PHP][Tutorial]Functions
Quote:
Originally Posted by
Dj.flames
What Makes You Think That Nub im Pro PHP I bet You Dont Even Know What PHP Stands For,
Dont Mess With The Best,
When You Chill With The Rest (Noob Rests Ahahah)
The fact you capitalize everything.
Oh here come some 1337 skillz.
"i knoewz wat php iz!!!!1111!!!One"
I've never used custom functions, so this helped me quite a bit.
Thanks.
Re: [PHP][Tutorial]Functions
Anyone who is knowledgeable in an area doesn't act like a bloody twat. Be humble, and thankful for what you do know... Just because YOU think it's easy and not helpful at all doesn't mean that it won't help a newbie. Also, stop using 'nub' and 'Pro.' First of all, I doubt you can tell me the difference between newb and noob without looking it up, secondly, that nub crap is stupid gaylo idiot talk, and third of all, this is a forum where 'programmers' support each other. 'Coders' are welcome, but if you can't teach it, then shut the hell up.
Back to the topic, well done mate. Although, next time, try and include a small php web page to show them what their results would be., you know, like using the input methods to change background color, as well as displaying text. You could even show them basic input boxes, or something similar, and show them how they can use that to trigger and manipulate the method to do on the fly transformations. I'm not as good at PHP as I should, but the function is similar to the way I'd do it in java
PHP Code:
private final void setPageProperties (java.awt.Color color, String name) {
pageBackground = color; // main color of page
titleBarName = name; // sets title to "My web page, by " + name
updatePage(); // updates and refreshes content to reflect these changes
}
That is, assuming that I'm using a small webserver in java :3
Re: [PHP][Tutorial]Functions
Actualy this tut is stupid.
1) Take vars out of quotes.
2) Do not echo in a function.
3) Use tabbing
You haven't told about Public, private and abstract functions. This is just beginner PHP...
Re: [PHP][Tutorial]Functions
Quote:
Originally Posted by
Guildjuhh
Actualy this tut is stupid.
You haven't told about Public, private and abstract functions. This is just beginner PHP...
I think this can actually be quite helpful for those who never before even thought of using functions. Not that it teaches much anything, but as an eye-opener.
Re: [PHP][Tutorial]Functions
Quote:
Originally Posted by
Negata
I think this can actually be quite helpful for those who never before even thought of using functions. Not that it teaches much anything, but as an eye-opener.
True, but it's not worthy to call a tutorial...
Re: [PHP][Tutorial]Functions
Quote:
Originally Posted by
Guildjuhh
True, but it's not worthy to call a tutorial...
That's true.
Re: [PHP][Tutorial]Functions
Any tutorial is worthy, as not everyone is not an elite coder like you. I don't see why you guys oppose simple tutorials, questions etc, when you once didn't know how to do the same thing. But now that you do, you act like everyone who does not know how to do it is no worthy of knowing. Which is quite selfish of you, regardless how you found out, you should be open to helping those who don't know as much as you, or simply allowing it, rather than opposing it. Anyways, great tutorial, and I'm sure that it'll help some of the not so elite coders we have here.
Re: [PHP][Tutorial]Functions
I don't want to be a total dick but please also teach standards properly;
PHP Code:
<?php
function func_Name($arg, $arg2)
{
if ($arg < $arg2)
{
return false;
}
}
?>
Indent with 4 spaces OR a "tab".
Re: [PHP][Tutorial]Functions
a tip if your going to make a if, foreach, for with only one line.. no need for braces
Re: [PHP][Tutorial]Functions
like this?
PHP Code:
<?php
function func_Name($arg, $arg2)
{
if ($arg < $arg2)
return false;
}
?>
Re: [PHP][Tutorial]Functions
Quote:
Originally Posted by
john_d
a tip if your going to make a if, foreach, for with only one line.. no need for braces
That's true. But I generally find that code harder to read. Of course it's entirely a personal matter, but I find braced code even for one-liners be more complete and clear. As long as you're consistent with your code-style :)
Re: [PHP][Tutorial]Functions
he means:
PHP Code:
<?php
if($hi==TRUE)
echo ' hello ' ;
else
echo 'hi';
?>
Re: [PHP][Tutorial]Functions
Quote:
Originally Posted by
Guildjuhh
Actualy this tut is stupid.
1) Take vars out of quotes.
2) Do not echo in a function.
3) Use tabbing
You haven't told about Public, private and abstract functions. This is just beginner PHP...
If you really hate this tut so much and think you could do it better, then make your own tut.
Re: [PHP][Tutorial]Functions
Quote:
Originally Posted by
Hidden
he means:
PHP Code:
<?php
if($hi==TRUE)
echo ' hello ' ;
else
echo 'hi';
?>
In which case I'd rather have brackets xD
PHP Code:
<?php
if ($hi)
{
echo 'Hello';
}
else
{
echo 'Hi';
}
?>
For me, when code gets too compact, it's really hard to read. I even add rows of slashes (////////) just to separate things and stretch the code.
Re: [PHP][Tutorial]Functions
other tips would be to learn how to use
die();
continue();
Re: [PHP][Tutorial]Functions
PHP Code:
<?php
function mathAdd($num1, $num2){
$answer = strval($num1) + strval($num2);
return $answer;
}
?>
Re: [PHP][Tutorial]Functions
Quote:
Originally Posted by
Hidden
he means:
PHP Code:
<?php
if($hi==TRUE)
echo ' hello ' ;
else
echo 'hi';
?>
I personally read simple if statements fine using this method:
bool ? if_value : false_value;
PHP Code:
echo ($hi==TRUE) ? 'hello' : 'hi';
But that's just me. If I'm using a system that will always only be one line, I'll do this method. If there's a possibility I'll put in more lines in the future, I'll use a longer statement just in case. However, for a function where it only takes a condition and returns true or false.. Like a function that checks if a user is a certain rank
PHP Code:
function check_rank($rank,$allowed_ranks) //$rank is needed, $allowed_ranks is optional array/PSL
{
if(strlen($rank)>0)
{
if(strlen($allowed_ranks)<1)
{
$allowed_ranks = 'Admin';
}
$allowed_ranks = ( count($allowed_ranks)>0 ? explode('|',$allowed_ranks) : $allowed_ranks );
$bool = if(preg_match('/'.$allowed_ranks.'/i',$rank)>0;
return $bool;
}
}
$permission_to_enter = check_rank($_SESSION['rank'],'Admin|Mod|Registered');
echo ( $permission_to_enter ? 'You May Pass.' : 'You Shall Not Pass!' );
Notice this line:
echo ( $permission_to_enter ? 'You May Pass.' : 'You Shall Not Pass!' );
There's really no need for further work on this line.It's simple, if the rank is allowed, say it's allowed. If not, say it's not allowed.
Simple, no? :w00t:
EDIT: Still, you all should look up and listen hard to Daevius, he pretty much taught me everything, so take me as a grain of salt in comparison. I'm just showing you all some other organization methods that you might personally like too ;)
It is always nice to keep decipherable code. I remember not too long ago I didn't understand the bool?true:false; method, and saw it as Chinese or something.. Now it makes more sense than english to me.. Do whatever is the best compromise between "best for you," and "best for the world," Always ;)
Re: [PHP][Tutorial]Functions
if statements depends on how they are needed
Code:
$this == true ? 'TRUE' : 'FALSE'
i generally use inside echo or variables declerations... since it would be a waste of time to do a full if statement.
and others like
Code:
if ($this == TRUE ) Die();
else {
echo 'it is not true';
echo 'probably false then';
}
of
Code:
foreach ($this as $this1 => $this2) {
if ($this2 == TRUE) continue;
echo 'FALSE STUFF';
}