Most voted "php" questions
Use this tag when the question refers to some resource, information, or problem relating exclusively to the PHP programming language. For example: questions about classes, methods, functions, syntax and general use of this language. Do not use this tag if PHP is used circumstantially, but has no relation to the question problem. For example: do not use this tag for questions about HTML formatting, CSS or Javascript code.
Learn more…27,244 questions
Sort by count of
-
14
votes2
answers4492
viewsIs there any way to foreach two variables at once?
I tried separating by comma, but it didn’t work: foreach($dados as $d, $telefones as $t){} I know there are other ways to do this foreach that work, but I wanted to remove this curiosity. It is…
phpasked 9 years, 2 months ago Amanda Lima 3,428 -
14
votes1
answer8177
viewsWhat’s the difference of using PHP as a module of Apache, CGI, Fastcgi and command line?
I wanted to know what difference there is between the various "versions" or "ways" to use PHP, as it has the module of Apache, CGI, Fastcgi and command line. So I wonder if there is any difference…
-
14
votes4
answers1052
viewsHow do we know the date is the last day of the month?
I have a date saved in the database and, before I present it on the grid, I need to know if it’s the last day of the month. I need this information to present it in a different color.
-
14
votes4
answers3299
viewsTyping the return in PHP 7. What are the advantages?
I was giving a test in PHP 7 and I checked that the same now accepts to define which type of data will be returned. Here are some tests: Defining the instance to be returned function test_object():…
-
14
votes2
answers6664
viewsHow to create and manipulate lists in PHP?
In java it is possible to create and manipulate list of any type of data using the List<E>, See the example below: List<String> lista = new ArrayList<>(); lista.add("Stack");…
-
14
votes3
answers19255
viewsWhat is the difference between while, for, while and foreach?
What is the difference between the while , do while, for and foreach in PHP, because they give the impression that same functionality. All of them can be used to create a loop or has other purposes?…
-
14
votes2
answers1408
viewsHow and when should we use Interface to document systems in PHP?
I always wondered exactly, if it is a good practice, to make a system always making use of Interfaces, or this is not necessary? Interface People { public function getName(); public function…
-
14
votes2
answers625
viewsIs it really necessary to use mutator and access (Setter and getter) methods in PHP? What about performance?
I’ve been noticing that most other libraries use the methods setters and getters (hereinafter referred to as mutator and accessor), to change the property of some classes. For example: class User {…
php performance pattern-design encoding-style getters-settersasked 9 years, 1 month ago Wallace Maxters 102,340 -
14
votes3
answers1028
viewsFacilitation in PHP projects
I work with PHP using Sublime Text and would like something similar to what it is in Eclipse. For example: In Eclipse I can open exactly where the method was declared. In Sublime Text I did not find…
-
14
votes2
answers2108
viewsAre function and method the same thing?
When we talk about methods and functions, we are talking about the same thing? For example: function blablabla blabla That is a method?
-
14
votes4
answers11575
viewsUse . env file in PHP project?
I realized that in the Laravel uses the file .env for some settings and in the code it a function env(), ask: Is there any way to use the file .env in my project php without using any framework? If…
-
14
votes3
answers2102
viewsWhat is the difference between function and array assignment?
I have recently been coding in my projects where I need to add items in an array, so I don’t know if I should use native language functions for this, for example: array_push($meu_array, 50); or if I…
-
14
votes3
answers262
viewsHow to validate strings?
I have the following strings: www.adorocinema.com/filmes/filme-226616/fotos www.adorocinema.com/slideshows/filmes/slideshow-124792 www.adorocinema.com/noticias/filmes/noticia-125494…
-
13
votes2
answers32948
viewsHow to send SMS for free using PHP?
I wonder if there is any way to send SMS for free to mobile phones in Brazil. I have seen some PHP systems with this function, and I would like to have this function on my system as well.
-
13
votes3
answers799
viewsFloats module in PHP returns integers?
How do I get the rest of the division (operation module %) with decimal places when using a divisor or dividend float? Example: echo 5 % 3; // imprime 2 como é esperado echo 5.6 % 3; // imprime 2…
-
13
votes4
answers20996
viewsDifference between null, Empty, 0 and false
The goal Differentiate the day-to-day use of null, empty, 0 and false. The problem Dealing every day with these 4 representations of variables is complicated and I don’t know how to differentiate…
-
13
votes3
answers48813
viewsReceive external JSON data from PHP
I am trying to receive an external JSON file via PHP. I am doing so: <?php $json_file = file_get_contents( "http://www.moonwalk.com.br/api/VitrineDeProdutos/58e903df295cbc5c4639434d4c35090d");…
-
13
votes3
answers3756
viewsProblem using subst in text with PHP
When using substr in a variable with text, it is returning a special character " "someone could help me? I’m using the following code: $excerpt = get_the_content(); $excerpt =…
-
13
votes2
answers1997
viewsHow to detect Ajax Request?
Is there any way in PHP to detect if the request made is Ajax?
-
13
votes2
answers9163
viewsHow to force files of type . txt to be downloaded
I have a page, but I don’t want you to click on files like . txt to download instead of displaying them. I am developing this page in PHP. I saw some scripts on the web, but it is forcing the…
-
13
votes3
answers317
viewsWhat are the most common problems and dangers when enabling `register_globals` in php?
I recently asked the following question How the file receives the $_POST? Based on the comments and the answer I was interested to know the main problems and dangers of having this function enabled…
-
13
votes3
answers759
viewsComparison between a numeric string and an alphanumeric string
The following operation returns true: var_dump("1" == "1e0"); //1 == 1 -> true But if I add an "e" at the end of the second string, it already returns false: var_dump("1" == "1e0e"); //1 == 1…
-
13
votes1
answer767
viewsWhy does PHP allow you to create identifier names with special characters?
Typically in programming languages and databases, identifier names (variables, functions, classes, methods, tables, fields, etc.) must start with a letter or underline, numbers can come in sequence…
-
13
votes4
answers452
views& Together with PHP operators and functions
What is the meaning of the use of & together with operators and functions in PHP because I checked in some libraries (example) and functions this use (I am aware of the use together with…
-
13
votes3
answers1055
viewsIs there any performance gain when using ternary operator instead of a conditional operator?
What is the difference in performance using conditional operators and ternary operators? Is there any significant gain or the choice of use of ternary operators is unique to code simplification?…
-
13
votes6
answers4694
viewsHow to make a stopwatch continue counting after closing the page?
I need to create a stopwatch that is started through a play, but wanted a solution, other than by SESSION, to let you count even if the customer closes the window or drops his internet, ie that is…
-
13
votes4
answers7944
viewsHow to take print (screenshot) from a web page?
I would like to know how to print a page, and save in image. Follow example for understanding:…
-
13
votes2
answers869
viewsWhat is Finally for in PHP 5.5?
PHP 5.5 implemented a feature (which I’ve heard exists in other languages) called finally, in the handling of exceptions (together with the try/catch) We have the following example:…
-
13
votes5
answers169
viewsWhat is the fastest is_null($y) or $y == null?
What’s the fastest is_null($y) or $y == null?
phpasked 9 years, 8 months ago Paulo Costa 3,976 -
13
votes3
answers2493
viewsHow to choose the highest value of an array?
I’m trying to use the function max, but I can’t hit. // variáveis da diferença salarial $saldev[0] = $_POST ["Tdate5"]; $saldev[1] = $_POST ["Tdate9"]; $saldev[2] = $_POST ["Tdate13"]; $saldev[3] =…
-
13
votes5
answers2967
viewsTake all the names and put comma to separate them
When I get the names and add them to a variable, I can’t separate them with a comma normally. has to be by comma and period at the end I can’t put each name in line break using It’s hard to explain,…
phpasked 9 years, 11 months ago Murilo Man 439 -
13
votes2
answers641
viewsDoubts with relationships in Eloquent
Guys I’m making a belongsToMany to recover several Users that are related to a Item. It returns me in the all array Users correctly, but I need to make a hasOne of each User(created on the model…
-
13
votes3
answers4752
viewsWhat is the difference between 'Yield' and 'Return' in PHP?
I have been trying to remove this doubt, but without success. At first glance they seemed to me similar commands or they would be the same thing. After seeing some explanations, I was a little…
-
13
votes4
answers1072
viewsWhat is the practical use of bitwise operators in PHP?
Operators bit by bit, used to manipulate specific bits, are somewhat unusual (not to say rare) their use in an application PHP. If we talk about escovação de bits in compiled languages, such as…
-
13
votes2
answers133
viewsget original HTML entities with javascript
I need all the original HTML entities of a paragraph, mainly the accents, the methods I know only recover some entities, as the example below where ">" is correctly coded but "ç" does not. It is…
-
13
votes4
answers31386
viewsSending email via Phpmailer to Gmail
I can’t at all send an email to my Gmail account via PHP. I had a previous project where I tried to use phpmailer and I can’t get it to work properly (2 months trying). Now I finished a website and…
-
13
votes2
answers315
viewsfilesize for files larger than 2GB on x86 platforms
I was reading the PHP documentation and I noticed this information: Note: Because PHP’s integer type is Signed and Many Platforms use 32bit integers, some filesystem functions may Return Unexpected…
-
13
votes1
answer7485
viewsLaravel 5 and Sql Server
I need a help, I made several attempts to connect Laravel with SQL Server and all without success. However, I managed to make it work with pure php, using sqlsrv_connect and Code Igniter. Windows 10…
-
13
votes2
answers460
viewsWhat is Closure Object and how do I get the anonymous function return as parameter?
Let’s say I have a class, and in that class i have a method, and in a parameter that method it is possible to use a anonymous function thus: Class and method: class Classe { private $exemplo = [];…
-
13
votes5
answers11978
viewsHow to get the current file name
I recently had a problem identifying the current page. Was using __FILE__ to get the current file, and used substr() to retrieve the string after the last occurrence bar, it turns out that in some…
-
13
votes4
answers320
viewsWhat is .= in php?
What is .= in PHP? I’m wondering if it’s a concatenation or multiplication.
-
13
votes2
answers995
viewsPHP 7 has argument typing and return, but is it optional. Is that good or bad?
I would not like to raise here a controversial issue regarding the PHP 7 language, which was released recently, but only understand a few points regarding typing. Come on: In versions prior to PHP…
-
13
votes5
answers1023
viewsWhat is the difference between starting an empty variable and starting directly with the value?
I see things like: $arr = []; $var = ''; $var; $var = null; What’s the difference between starting the variable like this: $var = ''; $var = 'teste'; And start like this: $var= 'teste';…
-
13
votes3
answers2365
viewsHow to verify if connected in the database?
how do I check my code PHP + PDO successfully connected to the database Mysql? With code like this it works: <?php /* Connect to a MySQL database using driver invocation */ $dsn =…
-
13
votes2
answers1270
viewsWhy is the NAN constant evaluated as True when testing it with is_numeric?
I was doing a test with the constant NAN in PHP, because until then I had never used it. I did tests out of curiosity. I noticed something interesting. When calling the function is_numeric in NAN…
-
13
votes1
answer363
viewsAre there differences between /, /* */ and #?
Considering how important it is to comment on a code, I came up with this question. I realized there are several ways to comment lines/parts of code: // /* */ # Example: // comentando uma linha /*…
-
12
votes2
answers396
viewsIs there a function to display the defined variables?
There is a way to give a "var_dump" in all instantiated variables in that context, without having to put each one inside the var_dump()?
-
12
votes5
answers21638
viewsCurrency formatting to save to database as DECIMAL
I am using a mysql database, the format of the field is Decimal (7,2) and he gets his salary. Based on what the user types I store in the bank so: str_replace(',','.', $_POST['txtSalario']) Replace…
-
12
votes8
answers56968
viewsPHP echo Special character problem ("ç")
I’m developing a website that displays the names of the months with strftime. HTML is already charset=UTF-8. The problem is that in the month name display it appears as in the image below I did a…
-
12
votes4
answers3355
viewsPHP login with permission levels
I have a problem with my code to separate logins. I want when a login with Rank = 1 it redirects to a page, and when the Rank is = 0 go to another. I tried to do it but I didn’t get it because he…