Skip to main content

All Questions

Tagged with
0 votes
1 answer
19 views

Why does the PHP spread operator in an Elasticsearch query return different results than hardcoding parts of the query?

I've got a problem that I'm not entirely sure I understand. I've got the following Elasticsearch query, written in PHP, with fuzziness matching hardcoded; this results in about an expected 1,500 ...
Martin Uildriks's user avatar
2 votes
1 answer
64 views

Why does calling a static method with only one colon not cause a parse error? [duplicate]

When calling the following code, I was surprised that a parse error was not thrown or other error given as this code does not look right. The colon in PHP has several uses, however, I've gone off the ...
SeanDowney's user avatar
  • 17.7k
-1 votes
1 answer
82 views

PHP - Why does division operation causes loop to skip rows of data

Completely stumped by this one. I have some code that pulls rows from a database and attempts to process them as part of a PHP while() loop. Here's the basic code: $i = 1; while (list($thisScoreID, $...
Eric Brockway's user avatar
0 votes
1 answer
146 views

Hide Shipping Method conditionally based on Shipping Class, Cart Quantity and Cart Total in WooCommerce [duplicate]

I am encountering some issues with my condition to check for cart total, amongst cart quantity and shipping classes. What I am trying to achieve I am trying to hide a specific shipping method ...
Richard's user avatar
  • 347
0 votes
1 answer
101 views

Writing an matrix alogrithm with multiple rules in PHP

I'm trying to write an alogrithm in PHP for this matrix: 'risk profile' is from 1 to 5. 'compliance score' is from 0 to 5. The scores are then plotted in the matrix and given a frequency result (in ...
jmiller's user avatar
  • 588
1 vote
0 answers
39 views

Why does the decrementing operator in PHP work in this way? [duplicate]

The following code: $arr = array(1, 2, 3, 4, 5); $i = 5; while($i >= 1){ var_dump($i); var_dump($arr[--$i]); } has the following output: int(5) int(5) int(4) int(4) int(3) int(3) int(2) ...
Sharanya Dutta's user avatar
-1 votes
1 answer
102 views

Is !empty($a) ? $a : $b the same as $a ?: $b in PHP

I'm working on a new project and I've come upon the question if the ternary short hand operator the same as using the traditional ternary in combination with the empty() function? For clarity purposes ...
Nicholas Gooding Rios's user avatar
3 votes
1 answer
176 views

Pass by reference when using splat operator (...)

I have two functions. One of them receive and modify some values in an array that is passed by reference. function dostuff ($param1, $param2, &$arr) { //... //add new elements to $arr } ...
CarlosCarucce's user avatar
0 votes
0 answers
20 views

PHP output newline in a single character using bitwise NOT operator

I have found in different web sites (for example here) this statement: This PHP code prints a newline using 10 bytes: echo "\n"; This PHP code prints a newline using 9 bytes: echo " &...
Mario's user avatar
  • 420
0 votes
2 answers
558 views

PHP How to take first 2 bits from byte and make new byte

Operations on bits. How to take 2 bits from byte like this: take first 2 from 12345678 = 12; Make new byte = 00000012 For example as asked in discussion by jspit : $char = 'z'; //is 122, 0111 1010 $b =...
Daro from Poland's user avatar
0 votes
1 answer
46 views

PHP bug or just a logical flaw

I need to know why, the real logical reason, that the following comparison is executing the "echo" line! It seems to be some kind of sorcery. If you take out the "+" sign, it won't ...
KonKarOtMa's user avatar
1 vote
0 answers
37 views

float casting *= equations in php

Currently using PHP 8.1, I hit fatal errors whenever I do a formulae such as String * Float. Ok, so I just fix it by float casting it, and it's solved. But I noticed another issue, is that float ...
Patrick Teng's user avatar
0 votes
1 answer
118 views

Bitwise OR operator in PHP, Bug or Feature?

echo 'https://www.tehplayground.com/' | '/'; Results in 'ottps://www.tehplayground.com/' Why?
Guilherme Carvalho's user avatar
-1 votes
1 answer
20 views

How to add a 3rd Option

I have this code snippet if (!empty($_POST['dropdownOption'])) { $orderBy = ($_POST['orderValue'] == "date") ? "date" : "price"; $orderType = (!empty($_POST['...
Robert Mallett's user avatar
0 votes
0 answers
35 views

variable operator to add or subrtact another variable

Im making a php math game where you have equations you need to solve in order to earn score. but heres the problem. i have 4 variables, $x, $y, $op, $b. $x is the first random number, $y is the second ...
S9U4R3's user avatar
  • 1

15 30 50 per page
1
2 3 4 5
36