LMSouq

Knowledge Base

Browse Moodle Solutions

2108 solutions found

Page 18 of 106
0 votes
1 ans
3 views
Access first level keys with array_map() without calling `array_keys()`

Is there a way of doing something like this: $test_array = array( "first_key" => "first_value", "second_ke...

php-dev Solved
JO
asked 1 month ago by José Tomás Tocino
0 votes
1 ans
3 views
PHP: merge two arrays while keeping keys instead of reindexing?

How can I merge two arrays (one with string => value pairs and another with int => value pairs) while keeping the string/int keys? None of them will ever...

database Solved
GA
asked 1 month ago by Garrett
0 votes
1 ans
3 views
Truncate a string to first n characters of a string and add three dots if any characters are removed

How can I get the first n characters of a string in PHP? What's the fastest way to trim a string to a specific number of characters, and append '...&#39...

php-dev Solved
AL
asked 1 month ago by Alex
0 votes
1 ans
3 views
List of Big-O for PHP functions

After using PHP for a while now, I've noticed that not all built-in PHP functions are as fast as expected. Consider these two possible implementations of a...

php-dev Solved
KE
asked 1 month ago by Kendall Hopkins
0 votes
1 ans
3 views
How to query all the GraphQL type fields without writing a long query?

Assume you have a GraphQL type and it includes many fields. How to query all the fields without writing down a long query that includes the names of all the fi...

database Solved
BL
asked 1 month ago by BlackSigma
0 votes
1 ans
3 views
Get URL query string parameters

What is the "less code needed" way to get parameters from a URL query string which is formatted like the following? > www.mysite.com/category/su...

database Solved
EN
asked 1 month ago by enloz
0 votes
2 ans
3 views
How should a model be structured in MVC?

I am just getting a grasp on the MVC framework and I often wonder how much code should go in the model. I tend to have a data access class that has methods like...

general-dev Solved
DI
asked 1 month ago by Dietpixel
0 votes
1 ans
3 views
How to get the last element of an array without deleting it?

Ok, I know all about [`array_pop()`][1], but that deletes the last element. How to get the last element of an array without deleting it? Here's a bon...

php-dev Solved
TH
asked 1 month ago by Theodore R. Smith
0 votes
1 ans
3 views
PHP mail function doesn't complete sending of e-mail

<?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $from =...

php-dev Solved
US
asked 1 month ago by user3818620
0 votes
1 ans
3 views
What is the difference between client-side and server-side programming?

I have this code: <script type="text/javascript"> var foo = 'bar'; <?php file_put_contents(&#39...

server-admin Solved
DE
asked 1 month ago by deceze
0 votes
1 ans
3 views
Convert a date format in PHP

I am trying to convert a date from `yyyy-mm-dd` to `dd-mm-yyyy` (but not in SQL); however I don't know how the date function requires a timestamp, and I can...

php-dev Solved
MA
asked 1 month ago by matthy
0 votes
1 ans
3 views
How can I connect to a Tor hidden service using cURL in PHP?

I'm trying to connect to a Tor hidden service using the following PHP code: $url = 'http://jhiwjjlqpyawmpjx.onion/' $ch = curl_init();...

php-dev Solved
FR
asked 1 month ago by frosty
0 votes
1 ans
3 views
PHP equivalent of .NET/Java's toString()

How do I convert the value of a PHP variable to string? I was looking for something better than concatenating with an empty string: $myText = $myVar ....

php-dev Solved
AN
asked 1 month ago by Antoine Aubry
0 votes
1 ans
3 views
Fastest way to check if a string is JSON in PHP?

I need a really, really fast method of checking if a string is JSON or not. I feel like this is not the best way: function isJson($string) { ret...

php-dev Solved
KI
asked 1 month ago by Kirk Ouimet
0 votes
1 ans
3 views
What does double question mark (??) operator mean in PHP

I was diving into Symfony framework (version 4) code and found this piece of code: $env = $_SERVER['APP_ENV'] ?? 'dev'; I'm not su...

php-dev Solved
EL
asked 1 month ago by elkolotfi
0 votes
1 ans
3 views
Are PHP short tags acceptable to use?

Here's the information [according to the official documentation][1]: > There are four different pairs of > opening and closing tags which can be...

php-dev Solved
MD
asked 1 month ago by MDCore
0 votes
1 ans
3 views
Check if PHP session has already started

I have a PHP file that is sometimes called from a page that has started a session and sometimes from a page that doesn't have session started. Therefore whe...

php-dev Solved
AR
asked 1 month ago by Arda
0 votes
1 ans
3 views
Laravel Add a new column to existing table in a migration

I can't figure out how to add a new column to my existing database table using the Laravel framework. I tried to edit the migration file using... <...

php-dev Solved
KI
asked 1 month ago by kim larsen
0 votes
1 ans
3 views
How to get the file extension in PHP?

I wish to get the file extension of an image I am uploading, but I just get an array back. $userfile_name = $_FILES['image']['name'];...

php-dev Solved
KE
asked 1 month ago by Keith Power
0 votes
1 ans
3 views
How to convert an array to object in PHP?

How can I convert an array like this to an object? ``` [128] => Array ( [status] => "Figure A. Facebook's horizontal scrollba...

php-dev Solved
ST
asked 1 month ago by streetparade