Posts by rray • 66,288 points
1,220 posts
-
4
votes1
answer124
viewsA: Resized screen after upgrading Xcode to version 11
The screen displayed as a modal (sheet) is not a problem of Xcode 11, this behavior happens from iOS 13 and derivatives (iPadOS) as announced in WWDC’s talk of 2019 Modernizing Your UI for iOS 13,…
-
3
votes1
answer71
viewsA: How to set 'default' keys and values for array passed as parameter in PHP?
Use array_fill_key() to generate an array with all the required keys and only one value for all. Finally call array_merge() which will merge the default array and the user passed array and the…
-
2
votes1
answer76
viewsA: Catch 6 numbers of a string within an array
You can take the first six digits of this string with a regular expression, ^\d{6}, the result of the capture is stored in $m. if does two checks, the first is if the capture of preg_match()…
-
1
votes1
answer38
viewsA: Print an enabled message on the screen after a validation
On the basis that $emailRetornado and $cpfRetornado comes from the database or is there already a previous record of this person. Change the logic to identify which of the fields already has some…
-
3
votes2
answers91
views -
3
votes2
answers804
viewsA: Regex for single quotes
You can solve this problem alternatively with str_replace() and substr(). First all single quotes are removed, then a check is made with substr() if the first and last characters are single quotes…
-
1
votes1
answer37
viewsA: Convert php array
You can format (Flatten) this array with PDO the first step is your query should return only two fields being the first the id (array key) and the second the value. When retrieving data use constant…
-
3
votes2
answers313
viewsA: Problems with array "Uncaught Referenceerror: Function is not defined"
Another alternative to this problem would be to use a data structure called set, its two main features are not allow duplicated elements and is not a classifieds collection. Logic is simplified in…
-
2
votes1
answer40
viewsA: foreach with error
To put the last date in the list it is necessary to add a day to its end date, with the method modify() $ini = new DateTime('2019-02-01'); $fim = new DateTime('2019-02-28'); $fim->modify('+1…
-
5
votes2
answers44
viewsA: Working with Array in PHP
Another way to get the same result is to use a foreach with a array_combine() this function create a new array where the first arguments defines the keys and the second the respective values, this…
-
3
votes2
answers184
viewsA: List year in the current year select to 10 years ago in descending order
Just use the function rsort(), if you want you can create an array with range(). <?php $anoAtual = date('Y'); $anos = range($anoAtual - 10, $anoAtual); ?> <select name="AnoInicio"…
-
10
votes1
answer400
viewsA: How to return the last value of an sql string?
Use the function RIGHT() it returns the(s) N character(s) on the right, the quantity is informed by the second argument. SET @VALOR = RIGHT('0000050529-G', 1)…
-
2
votes1
answer137
viewsA: How to pass mysql table field name as parameter via PDO PARAM?
Use preg_match() to define which characters are valid for an identifier (alias name) this defaults an Injection sql attack. Basically the regular expression says to look for one or more characters…
-
3
votes1
answer44
viewsA: Compile "com.android.support:appcompat-v7:27.1.0" error
The documentation has a list of which directives should be used in place of the obsolete ones and recommends using the exact version number to avoid dynamic dependency problems. In case it changes…
android-studioanswered rray 66,288 -
2
votes4
answers915
viewsA: Convert date format to php
You can assemble something simpler than suggested in the link. The first step is to define two arrays one for search and one for substitution (from Portuguese to English) because the names of the…
-
3
votes3
answers75
viewsA: How to calculate a FOR for 6 in 6 increments it give an echo?
Can you check whether the $i is mod (which checks if the division has no rest) of 6 then print the page number. if($i % 6 === 0) echo $i; Another simple example: foreach(range(1, 60 ) as $item){…
-
2
votes1
answer84
viewsA: I am not able to enter data in the database
The code has two problems, the first is the lack of associating the values with the placeholders the function bind_param() does this. The second lib Mysqli does not support named placeholders…
-
2
votes1
answer300
viewsA: PHP - How to find the least common element in an array
I decided to break the logic into three parts (functions) the first is how to assemble the array of selected numbers, the second the display of the largest and smallest and the last check which…
-
2
votes1
answer134
viewsA: Check if number is available within a defined range
The ideal is to convert these two strings into two arrays with explode(), this way can obtain the difference (the elements of $todos who are not in $disponiveis) with the function array_diff()…
-
4
votes2
answers555
viewsA: Difference between fetch and setFetchDP methods
Optionally fetch() and fetchAll() may have the default format changed by passing the respective constant as argument. Its advantage is to use a format other than the standard at a specific point in…
-
3
votes1
answer32
viewsA: Capture part of the string between certain repeated characters N times
To capture more than one occurrence it is necessary to use the function preg_match_all() the married values are inserted in the third. Use a simpler regex, case the value of the keys in a group $str…
-
5
votes2
answers446
viewsA: How to take 2 PHP arrays and join in 1 string
Can use array_map() to take the repective values of each array (par to par) and within the anonymous function assemble the format and/or sanitize the string. Since the function return is a new…
-
7
votes3
answers7703
viewsA: Remove last number with sql
Can combine the function left() to pick up all characters starting left until the limit is set by len() (which returns the string size) -1. Something like: select…
-
2
votes2
answers212
viewsA: mysqli_prepare() expects Exactly 2 Parameters, 1 Given
The function mysqli_bind_param() asks for two arguments the first is a string that defines the types of the following arguments, as it seems to be strings use s Change: public function cadastro…
-
3
votes3
answers277
viewsA: Using regular expressions with square brackets
Just undo the brackets with the escape character (\) and say that one or more occurrences should be replaced with +. This regular expression will fail in cases where the string is badly formatted,…
-
3
votes1
answer71
viewsA: Failed to read file. CSV
You can treat this Warning by setting a default array if the result of preg_split() not expected. Basically check if it is null and assign the default array. Other alternatives to preg_split() sane…
-
5
votes3
answers253
viewsA: Comparison between PHP and mysql variables
You can solve this problem by converting this string ($row['block'] in an array with the function explode() finally just compare with in_array() if the value ($id) available in the list of blocked…
-
3
votes1
answer327
viewsA: Remove Part of String with PHP
You can use the function strstr() to break and get the left piece of the string, an important detail is to inform the third argument that returns the left part, by default returns the right. $str =…
-
1
votes5
answers2538
viewsA: How to use Try Catch on an Insert
By default PDO emits errors in unsuccessful query, since errors and exceptions are distinct things especially in php. The simplest way to treat a failure is to catch the result of execute() $sql =…
-
3
votes5
answers1540
viewsA: Check that all $_POST was shipped without using too many ifs
From the php5.5 empty() started to evaluate expressions and not only variables. One way to solve the problem is to connect all fields through conjunctions (commonly E logical) and let the if handle…
-
13
votes1
answer1046
viewsQ: What are the differences between Treeset, Hashset and Linkedhashset?
The idea of Set is to not allow repeated elements, in java there are three implementations TreeSet, HashSet and LinkedHashSet found some differences in that reply, would like to know in detail if…
-
2
votes1
answer28
viewsA: Return days of the year, removing those that are in a Variable
You can solve this problem with the following steps, generate a date range (the calendar of the year itself) with the help of the classes DateInterval and DatePeriod defining the increment unit…
-
0
votes1
answer83
viewsA: UPDATE problem and WHERE clause with two conditions
The problem seems to be the fact of the placeholder cdata serve two purposes (search and be the new value). The primary key should be enough to find the record in which case you should, remove cdata…
-
0
votes3
answers229
views -
0
votes3
answers82
viewsA: Common conveter array in associative array
There are two ways to do this, the first with array_column() that extract a column/key from an array that in case will do this twice, one to name and another to value finally array_combine() creates…
-
8
votes1
answer52
viewsA: How to decrease this code in PHP?
You can do so by adding parentheses when creating the object you can already call some class method. $abre = (new DateTime($abre))->format('H:i'); $fecha = (new…
-
2
votes1
answer741
viewsA: How to capture mysql (Duplicate entry) error and display a message on the screen to the user using codeigniter?
The solution to this problem is to take the sqlstate and check if it is 1062 (Duplicate entry). Use the method error() in case of failure it returns an array with the code and the description of the…
-
1
votes2
answers5430
viewsA: How is a multi-valued attribute represented?
In multi-valued attributes database can be specific types such as an array, set, json etc. In most cases it is using a varchar (which usually indicates a problem in the modeling) such as for example…
-
4
votes1
answer705
viewsA: PHP Return AD user
The sAMAccountName is the login, so to recover it put this field in the selection of returned attributes. $attributes = array('name', 'sAMAccountName');
-
2
votes1
answer107
viewsA: Pass parameter to template with Smarty
Yes, it is possible. Use the method assign() Smarty two arguments are passed the first is identifier which value will have and the second the value itself. $template->assign('lista', $modelos);…
-
2
votes1
answer42
viewsA: PHP check specific characters
One way is to use a regular expression to validate the specific format. [a-z0-9] means that only letters (a-z) and numbers (0-9) will enter the capture. $str = '12345-67819-10111'; $regex =…
-
1
votes1
answer64
viewsA: How to format date variable in Smarty for dd/mm/YYYY
Smarty uses some standard php functions for some things like in the case of dates strftime() the formatting rule is the same as in documentation date_format is essentially a wrapper to PHP’s…
-
4
votes2
answers897
viewsA: Separate equal values in an array
Use array_column() to get all available groups, then just do a foreach by passing as key the current item (group) and the value the full item. $grupos = array_column($produtos2, 'GRUPO'); $novo =…
-
0
votes2
answers31
viewsA: Error comparing php array
You can solve this by checking if the index exists with isset() the if condition should be composed in this way: if (isset($rua[$i+1]) && $rua[$i] == $rua[$i+1]) {…
-
4
votes4
answers132
viewsA: Assign a value to a variable when the search return is NULL
Another option is to use the identical operator === when comparing the values. $IdSetor = ($IdSetor === null) ? 0 : $IdSetor;
-
5
votes1
answer726
viewsA: Data returned in an array is duplicated
By default the return of PDO queries is the PDO::FETCH_BOTH which returns duplicated data being an index with the field name and another numeric index. You can define the data format in three ways:…
-
5
votes1
answer75
viewsA: Merge two arrays
Can use array_map() to match the values of the arrays $tamanho and $quantidade in a new with the desired indices: $tamanho = ['P', 'M', 'G']; $quantidade = [1, 3, 5]; $novo = array_map(function($t,…
-
2
votes2
answers99
viewsA: Handler for undefined index in array
To check if the key exists even if the value is null use the function array_key_exists() in place of isset() may attach this verification to the second if. $item_anterior = ""; $array =…
-
2
votes2
answers15763
views -
4
votes3
answers457
viewsA: How can I return zero in front of other numbers?
If size is fixed, use the function str_pad() to add variable number of zeros left being at most four digits and at the end can concatenate the letter. $formatado = 'A'. str_pad($soma, 4, 0,…