Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Way 1:
public $foo = 1;
function(){
return $this->foo+1;
}
Way 2:
// with $foo = 1 in other function
function($foo){
return $foo+1;
}
Sorry for a 'dumb' question, someone can tell me what is the better way?
Second way is better and it is more canonical than first one. For more information please read this doc http://php.net/manual/en/functions.arguments.php
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Is it possible to call a function without javascript/Jquery/Ajax in one PHP file.
<?php
$connect = mysqli_connect("localhost","root","","");
Permit
function permit_access() {
$permit = mysqli_query($connect,"UPDATE permittable SET confirm = 1 WHERE id = keyid");
return $permit;
}
?>
This is not possible.
I would recommend you read about "server side scripts" and "client side scripts".
They live on different planets. :)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Is there a way to make something like this:
$bob = $request->bob;
return $bob in_array()....
to resolve to something like
return ! in_array()....
or
return in_array()....
base on the variable value...
You can use ?:
return $variable ? in_array('x', $some_arr) : !in_array('x', $some_arr);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
For example str1 = "hello world",str2 = "hello wordl",they have the same length,but are not same
You can use levenshtein.
If (levenshtein($str1,$str2)===0){ // identical}
Yes It is possible. you can use strcmp for string comparison.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a project with lots global variables.
Examples used in functions
function ChangePassForm( $VARS ) {
global $tpl, $iBtns, $db;
...
$db->query("....");
}
I can pretty easy guess what the question is:
"Why is it not working"?
ANSWER from PHP.net:
Anyway I voted to close the question.
#Piotr please refine the question or it will be closed.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to avoid creating another file just to escape the namespace.
Found the solution. For others interested see below.
namespace { function myFunction() { ... } }