Skip to content
Advertisement

Tag: variables

PHP variable “default value”

I want to get a value from the session, but use a default if it is not defined. And ofcourse I want to circumvent the PHP notice. You can write a function that does this Example in action Is there a way to do this without defining this function in every file? Answer From PHP 7, you can now use

how to check if PHP variable contains non-numbers?

I just want to know the method to check a PHP variable for any non-numbers and if it also detects spaces between characters? Need to make sure nothing weird gets put into my form fields. Thanks in advance. Answer If you mean that you only want a value to contain digits then you can use ctype_digit().

PHP function with variable as default value for a parameter

By default a PHP function uses $_GET variables. Sometimes this function should be called in an situation where $_GET is not set. In this case I will define the needed variables as parameter like: actionOne(234) To get an abstract code I tried something like this: which results in an error: Parse error: syntax error, unexpected T_VARIABLE Is it impossible to

PHP | define() vs. const

In PHP, you can declare constants in two ways: With define keyword Using const keyword What are the main differences between those two? When and why should you use one and when use the other? Answer As of PHP 5.3 there are two ways to define constants: Either using the const keyword or using the define() function: The fundamental difference

PHP Pass variable to next page

It seems pretty simple but I can’t find a good way to do it. Say in the first page I create a variable And the form’s action for that page is “Page2.php”. So in Page2.php, how can I have access to that variable? I know I can do it with sessions but I think it’s too much for a simple

Convert a String to Variable

I’ve got a multidimensional associative array which includes an elements like I’ve got a strings like: How can I convert the strings into a variable to access the proper array element? This method will need to work across any array at any of the dimensions. Answer Quick and dirty: Of course the input string would need to be be sanitized

Advertisement