Questions tagged as 'php'

2
answers

How to shorten the process of creating an array without the need to write all indexes?

For example, if I need to create an array with 20 spaces, do I always have to do this? $teste = array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19); Or is there any way to shorten this process, from 0 to 19? Something like: $teste =...
asked by 30.06.2017 / 19:38
3
answers

How to make a foreach for an array of arrays?

How can I make a foreach for an array of arrays like this: array ( [option1] => 2 [option2] => array ( [name] => "ola mundo" [id] => "123456"...
asked by 03.10.2014 / 16:55
3
answers

How to delete folders, subfolders and files?

Using my example below, I can delete a folder and the files it contains: $uploaddir = "../img/uploads/".$destino_sa."/"; $dir_contents = scandir($uploaddir); if(is_dir($uploaddir)) { foreach($dir_contents as $content) { unlink($upl...
asked by 08.05.2014 / 04:14
2
answers

What is the logical operator "XOR" in PHP? When to use it? What he does?

I wonder what this XOR operator is? When to use it? And what does it do in PHP?     
asked by 22.01.2015 / 16:24
4
answers

Even or odd of an array in PHP

I need to create an array and tell if the values inside it are even or odd. I made the code this way: <?php $par_ou_impar = array(2,3,4,56,5,42,98,100); for ($i = 0; $i < count($par_ou_impar); $i++){ if ($par_ou_impar % 2 == 0)...
asked by 31.01.2016 / 18:18
4
answers

PHP's unset () function can improve performance?

I think the answer to my question would be "yes.", why I end up doing it in my code (when I remember), but I just stopped to think about it now and somehow I'm worried if someone I would not know how to answer the "why" of it satisfactorily....
asked by 30.07.2016 / 21:36
5
answers

Should I check dates with DateTime or regex?

I've seen two different ways to check if a date is valid. In a "modern" way, with DateTime : $date="2014-02-04"; $dt = DateTime::createFromFormat("Y-m-d", $date); return $dt !== false && !array_sum($dt->getLastErrors());...
asked by 04.02.2014 / 19:42
4
answers

How to upload images using CKEditor?

I'm building a Knowledge Base system and I'm using CKEditor to edit the texts, but I wish I could make UPLOAD of images within the text. I'm using PHP with MYSQL and the text part is already working. How can I upload images within CKEditor...
asked by 21.09.2016 / 21:15
2
answers

What is the difference between $ var = function () and function var ()?

I wonder, what is the difference between: <?php $var = function() { return 5; } $var(); and ... <?php function var() { return 5; } var(); What would be the difference between them? When to use them?     
asked by 22.05.2015 / 23:02
4
answers

Convert month number to name

I need to convert the number of the month to the name of the same, but it has to be in Portuguese (and preferably without the need of substr ) I can do this, with the default language in English $monthNum = 3; $dateObj = DateTime::...
asked by 17.06.2014 / 15:57