Questions
Browse questions with relevant PHP tags
1,088 questions
Has recommended answerprint numbers between two ranges in PHP? [closed]
For a solution that is both efficient and easy to read you could use something like this: foreach ([...range(1, 48), ...range(114, 118)] as $number) { echo "$number "; } This makes use ...
PHP forach array with objects
As per its documentation, the DateTime class doesn't have any public properties. You need to use the documented getTimezone() function instead, if you want to retrieve the timezone. Since the timezone ...
form serialize is not working after ajax request
Your form data isn't serialising because let $form = $button.closest('form'); doesn't match an object, therefore $form is empty. It doesn't match anything because the button isn't inside the form. ...
How to pass data to a webserver [closed]
index.php: <?php declare(strict_types=1); $encoded = json_encode($_GET ?? null); assert(is_string($encoded)); is_string($encoded) && error_log($encoded); You find it in the error log you'...
Laravel 11: Is it possible to force PHPUnit to trigger / "press" CTRL+C to simulate interruption of an artisan command?
With pcntl_signal() you register the signal handler. with posix_kill() you can send a signal (cf. kill(1), full example on the PHP manual pcntl_signal page). Now if you have the process id (PID) of ...
php.ini Path Disagreement
I'm actually glad you're asking this question in this direkt form: Is this a disagreement? Let's see the observations again: From my browser, running a php which invokes phpinfo() yields: /etc/php/8....
PHP webDav client gives ClientException: SSL certificate problem: unable to get local issuer certificate
Run composer installer that also ships with the certificates. Then use the composer diagnose command to verify they are available. Then retry with the webdav PHP script. It is perhaps already solved ...
When will a laravel model creation fail without an exception?
$team = Team::create($validated); Given that team was actually created (as a new class), $team will be that new object. Therefore, in the very unlikely event that no exception was thrown albeit not ...
Count file lines containing a 3-letter palindrome outside of square braces which has a corresponding inverted palindrome inside of square braces
Because only 1 qualifying palindrome is all that is needed to deem a line as valid (a counter), there is no need to use a lookahead to potentially make multiple matches in a single line. Capture the ...
CodeIgniter and Ajax: Dynamic Dependent Dropdown not working
In the View markup, identify options reliably by assigning the database id as the option value attribute value. In the great majority of cases, relationships should be built on ids, not names. <...
Missing required parameter for update route laravel 11
In Form <form action="{{ route('updatetransaksi', ['id' => $id_penjualan]) }}" method="POST"> use route() instead of url(). URL route won't automatically resolve named ...
Dynamic menu building and navigation using URL parameters PHP [closed]
First, let me bring to your attention that the $activeItem parameter of generateNavMenu() is never used -- that indicates that a re-think and some editing is required. Second, when a pg option is ...
Event Color based on Resource / Room Color - Fullcalendar.js PHP MySQL
As per the eventDisplay documentation, by default you will only see the dots on timed events in the dayGrid view, not the coloured rectangle. If you want to see that coloured rectangle in the dayGrid ...
Database locked in PHPUnit tests only
Have one database for your application and another for your tests. PRAGMA journal_mode=WAL That is the sqlite write ahead log. You observed that enabling WAL prevents the locking during the run of ...
How to force column to be in array if it matches the whole thing?
Because we don't have sample data to test against and because future researchers might need explicit checks for 2 and 8 (not just two rows which contain 2 or 8 which might unintentionally match ...
jQuery Ajax call returns the whole php file raw code
Make sure you're using a proper webserver and accessing the HTML file via http://localhost/index.html in your browser (assuming you're testing this on your local machine), that your webserver has ...
Create multidimensional structure from grouped aggregate data from an Eloquent query
I find your desired output structure to be a little unwieldy. It might make better sense to declare the deeper gender-specific data points as simpler associative elements genderCounts => ['male' =&...
Finding all types of end-of-line delimiters in a file [duplicate]
Let me guess, you are a developer who wants perfect identification of newline sequences regardless of the environment AND you want to keep all of your hair? PHP has had a solution for this for a long ...
Auth::user() / auth()->user(), undefined method 'update'
You can't use $user->update();. update() is used on query builder or Eloquent model instances only Change $user->update(); to this $user->save(); FYK (Eloquent model) $user = Auth::user(); $...
PHP Add 0.1 to 0 value for every two weeks past a specified date?
PHP's time() and strtotime() both reports time in seconds. To know how many weeks there are between your specified date and now we can do: $startDate = '2024-05-26 00:00:01'; $secondsInWeek = 60 * ...
Find Assignation in Condition using a Regex
You can use this /if\s*\(\s*[^!=<>\n]*=[^=\n]*\)/ Example FYI: I don't know what you're trying to archive. I have provided a solution based on your question. (Regex)
Upgrade from php 5.5 to php 8 error (string * int) fix in common
The "Unsupported operand types: string * int" error would only occur if you actually try to multiply text that can't be automatically juggled to a numeric value. e.g. $x = "test" ...
Replace a static build of data with a dynamic way
I don't know exactly what you are doing AND it doesn't look like good practice, but if you want to search for data based on your generated numeric values, create a lookup array with those numbers as ...
issue with Cube Positioning in Multiplayer Game
There's a logic error. Your PHP code always updates player 1's position if the session username (presumably the logged-in user?) matches the posted username. But both players can't be player 1! Your ...
Laravel API resource Group by and details from same table
There are a few ways to do this. Since you're using resources, you can play around with this In DetailResource public function toArray($request) { return [ 'id' => $this->id, ...
Stop PHP from clearing a form
It's not php which clears the form. Php doesn't run in your browser. Your browser posts back the form, which means it discards the page it was displaying and loads whatever the URL the form was posted ...
Group 2d Laravel collection by two columns and sum a third column within each group
Feeding a 2-element array to the groupBy() method only makes more work/handling because it generates an unnecessarily deep structure. Notice how Mohammad's snippet has to reindex (values()), then ...
Matching Keys and getting value in PHP or jquery
A pivot query will be the sensible play here. Group by the product ids, then write conditions to require certain Key-Value pairs. Use a prepared statement. How you execute that prepared statement ...
Reverse the order of parenthetically grouped text and reverse the order of parenthetical groups
I don't know how well this will hold up on varied input, but it is designed to be recursive in its splitting, reversing, imploding behavior while preserving the first entry's position in each ...
How can I call a REST API in Php
Any http client written for php such as curl or guzzle can do it. You can even use file_get_contents if you enjoy torturing yourself. As for the specifics of what to put in the requests, that can only ...
htmlspecialchars() default flags
The default value when passing no $flags parameter is ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 The second part... When neither of ENT_COMPAT, ENT_QUOTES, ENT_NOQUOTES is present, the default is ...
How to Add SSL Certificate to Outdated CakePHP Website with Apple FileMaker Server?
An SSL Certificate can be used independent to the underlying Web application as you can make the SSL connection terminate before it reaches the application. Then the traffic is still SSL until the ...
in PHP does pg_query_params takes into consideration the type of parameter passed?
So where is explained what exactly pg_query_params does when called from PHP ? There is no obligation to explain it, however the sources should be freely available and that is what it defines it. ...
PHP combine two associative arrays with different keys
array_merge will get you most of the way there. I see no evidence that "keys which are not present in both arrays are removed", as you claimed. Before the merge, a quick loop to add in keys ...
Append associatve elements to each row while looping a mysqli query result
Append the additional data using the union operator. while ($row = $table->fetch_array(MYSQLI_ASSOC)) { $containers[] = $row + [ 'tkoSum' => $this->getTkoSum($row['id']), ...
Abstract __construct with variable argument count
So here is my question: is it possible to define a "universal" constructor that will fit all of my NestedDTO? As so often, it depends. What you'd like to do is not possible any longer since ...
How to make a component in module of laravel
Auto-discovery of components is only within the app/View/Components directory and resources/views/components directory. These are the "main director[ies]" only. However, as the yours in ...
Install ext-ftp extension using the official docker image
Given the Docker image in question is actually or identical to docker.io/library/php:8.3-fpm@sha256:28cfad4b9dfb7c378d861a757a9253e47cc8165b724f113160146fa8a41b48e1 and that you have tried docker-php-...
Why can't `$request->user()` be accessed in global Laravel middleware even when the proper prerequisite middleware is called?
As far as I know, to use $request->user(), the session middleware must have been executed before this. auth()->user() works independently of the request’s initialization state because it ...
How to create an environment-aware configuration in Laravel 11?
This code might be simpler to what you currently are using: Add this in any service provider register function: public function register() { parent::register(); if (!File::exists(...
Does usort() behave differently in php 8.2.0 vs php 7.4.33?
As previously mentioned, PHP8 implemented stable sorting and any versions before that made no promises about preserving the original element order. As for cleaning up your code, it can be reduced to ...
Writing a regex regular expression to detect IN conditions with the same column name and replace them
If the values in your SQL are coming from variables (that are not completely in your control), then a prepared statement should be generated and the values should be passed in as parameters relating ...
Why do my PHPUnit tests in NetBeans run but don't result in any code coverage?
It's not entirely clear from your question where the configuration gap is, but this one clearly is wrong, and I'll explain afterwards why: <?xml version="1.0"?> <phpunit> <...
Split text by <br> in PHP scraping result
If you are going to iterate through an array if urls, you'll need to couple instructions or a parsing function with each url. For the provided url, I'd use XPath to target the desired content. Code: (...
PHP Mail to Googlemail. SPF only
Google has a lot of published guidance on this topic: Requirements for all senders Starting February 1, 2024, all email senders who send email to Gmail accounts must meet the requirements in this ...
Why mysqli_fetch_assoc reports an exception from a nested loop
I believe you have discovered a bug in mysqli. It looks like the bug has existed since at least PHP 7.4 and has not been fixed until now. To understand this, you need to understand that mysqli keeps ...
null value that should not exist
You're not handling null chaining correctly. You've got this: {{ $user->city && $user->city->country ? $user->city->country->name : 'N/A' }} Which is OK, but then right ...
Why shortcode @php() interfere with @php and @endphp
The issue in my view is the order of operations when processing @php blocks. The relevant source code will first store uncompiled blocks before it actually compiles anything. Uncompiled blocks seem to ...
Can't delete file properly, error 404 not found
In HTML, create a proper DELETE route <form action="{{ url('/pengaduan/delete/'.$data->id) }}" method="POST" style="display:inline;"> @csrf @method('...
how to create subarray into main array [closed]
The problem is that you're adding the second row data to the top level of the array, instead of as an item underneath the main row. This should help: while($rowA = $resultA->fetch_assoc()) { $...
Simply submit a proposal, get it approved, and publish it.
See how the process works