Skip to content

List all json files from folder then sort by date and paginate it

I need help to make it work. I’m using this code for list all json files from folder and paginate it and this works well. But how can I implement sort by getMTime() and krsort()? I want the last modified files at first. Answer Store the mtime values in a separate array, then sort by them with usort. Bef…

Running PHP commands gives Xdebug errors

I’m currently getting some weird error messages whenever I run which php or php –ini: I currently have 4 php versions in my /usr/local/etc/php folders: currently using php7.3 as my default php version. I’m planning to remove older php versions if that doesn’t cause much trouble. Can so…

SESSION in laravel for page protection

I want to make a Login Registration system in laravel 8. In which User when login only can access a particular page else redirect to login page. I did this like that. what’s wrong in it. //Login Code //Session Code Answer you can use the default authentication in laravel8 using laravel application Jetst…

How can I add a parameter to a callback function like in JavaScript?

I wanted to make a small function that let’s me connect to the database, do something in a callback function and then automatically close the connection like so: Usage would be like this: Is it possible to achieve this somehow? Because my mysqli_conn doesn’t seem to work. How to do it? Answer Supp…

Get dependencies Ids Algorithm

I have this problem and I came out with a solution but what is the best way to solve this problem ? Thank you in advance. Given an array of strings and an array of tasks you need to return a sorted array with tasks and dependencies tasks ids. Example: Expected output: So far this is the solution I built,

Using an array as request headers in PHP

I’m trying to send a GET request to an API using PHP stream_context_create and file_get_contents. I need to add API keys to the headers of my request, I’m storing these in an array so I easily edit them later and use them in multiple functions. What is a good way to include these arrays as headers…

Can I use the same table to represent different Entities in Symfony?

I am migrating an old PHP project to Symfony. I am trying to create the entities based on the existing database schema which I can not change. I am facing a problem : There is a table that would represent two different entities. Basically, there is a boolean (a tinyint(1)), if the boolean is false, then the r…