Questions tagged as 'php'

1
answer

How can I set a value in a specific variable in a function with optional attributes?

I made the following code to illustrate my problem: function teste($valor1 = '', $valor2 = ''){ echo "Valor1: " . $valor1; echo "</br>"; echo "Valor2: " . $valor2; } A very simple function, if I do this: teste('aqui',...
asked by 05.03.2018 / 15:47
3
answers

How to sort the query in the same order as an array used in WhereIn?

I would like Laravel to return a list of products where the ID belongs to this array: [12,5,1,8,16] , but sort by id according to array order! * What I have so far: $produtos = Produto::whereIn('id', $ids) ->orderBy( adici...
asked by 05.12.2017 / 15:30
1
answer

What does the namespace really look like? [duplicate]

I would like to realize the great need and utility of namespaces in the MVC architecture. In what circumstances does the use of namespaces become indispensable? Give an example of a concrete case if possible.     
asked by 07.04.2017 / 15:43
3
answers

How to get ip from a user using php?

I'm using the getenv("REMOTE_ADDR") function to get the ip of users who enter a certain page of my site and then I made a if to redirect that ip that is not equal to the variable of ip allowed. But when I play...
asked by 23.01.2017 / 21:49
3
answers

How to test if an instance is dynamic or static?

Let's say you access an object that you do not know how it was created and wants to know if it was instantiated as new \Acme\Foo() or if it was just returned \Acme\Foo ; What is the most practical test? (removed the requirement "...
asked by 21.07.2014 / 21:43
1
answer

Call PHP function onClick HTML button

I want to call a PHP function that I have on the same page, in the HTML button. My PHP function: if(isset($_POST['insert'])) { insert(); } function insert() { $requete = "INSERT INTO \"event\" ( title,...
asked by 22.10.2014 / 15:51
1
answer

What is the purpose of stdClass in PHP?

What is the purpose of the stdClass pre-defined class in PHP? In detail what does it do? How important is it?
asked by 04.06.2016 / 22:25
4
answers

Generate random random string in PHP

How to use the PHP language to generate a string, preferably with configurable size, random enough to be used in routines that handle encryption and that for security reasons can not be not too random? If you propose more than one solutio...
asked by 15.02.2014 / 20:20
1
answer

Why does print_r print before echo?

I have the following array : $array = array(10,20,30); print_r($array); Output: Array ( [0] => 10 [1] => 20 [2] => 30 ) If I print with echo before print_r : echo 'primeiro: '; print_r($array)...
asked by 07.05.2018 / 18:46
1
answer

The function to get the day of the week of PHP has limit?

I'm making a calendar using PHP and JS and it worked perfectly between the year 1902 until 2037, because from 2038 the function to get the day of the week in PHP returns an incorrect value. Is there any specific reason for this? Follow the co...
asked by 09.07.2018 / 04:41