All Questions
220 questions
5
votes
2
answers
349
views
PHP Fisher-Yates shuffle with random_int
The PHP manual states that the regular shuffle() function isn't cryptographically secure, but that random_int() is. I thought, ...
2
votes
2
answers
102
views
delete multidimentional array value in php
I made a program that converts JSON to a PHP array and checks every value of the multidimensional array with a loop and if a value matches certain values then it deletes that key and value and ...
2
votes
1
answer
127
views
function to group data by parent branches
I wrote this function to take database output like from PDO's fetchAll(PDO::FETCH_ASSOC) and turn it into a tree. For small datasets it works well. However, when ...
4
votes
3
answers
1k
views
Filter an array, but remove the filtered elements
I needed a PHP function that would filter values from one array into a new one, while also removing those values from the original array. After looking through the docs, I didn't see any such function,...
0
votes
1
answer
89
views
PHP assign values within in_array
What is a more efficient way of writing this sample code? Its purpose is to create a variable for days of the week based on a numerical value. This data is obtained from user input checkboxes. If the ...
4
votes
2
answers
186
views
Modify a WordPress loop to show posts of certain categories, based on user roles
I've got some code that works as intended, but I have a feeling that it's messy. This code is modifying a wordpress loop and the goal is to check the roles of the current user and show posts of ...
1
vote
1
answer
158
views
implode on two level dimensions array
I have an array like this
...
3
votes
1
answer
140
views
a php function to check a 'deep' array value
I've just coded a little function to check and get a deep array value. Basically, I need to return the value or null if it's not set or does not exists, or in general not useful for databases records. ...
2
votes
2
answers
626
views
remove ALL duplicate elements from an array
I have this code to remove duplicates (all occurrences) from an associative array, does PHP have methods to do this ? Or is there a way to improve the code ?
I looked for array_unique, array_search, ...
3
votes
3
answers
607
views
Find common timeslots for consecutive days
Imagine you want to reserve a classroom over several days. You get a schedule, from the school, telling you when a certain classroom is still free. To make it easy for your students, you want to ...
2
votes
2
answers
2k
views
Sort array of dates
I have this array with dates. All the dates are checked before creating the array with preg_match and check_dates.
GoodDates (
...
1
vote
1
answer
2k
views
PHP Group associative Array duplicates and make subarrays of different values
I have this type of table:
...
1
vote
2
answers
102
views
Check URL for keywords [closed]
I'm looking at improving my PHP knowledge and wondering if anybody has any tips on improving and optimising my function below?
...
2
votes
1
answer
325
views
PHP update multidimensional array values from same path multidmensional array
I need to update a multidimensional array by same key paths of a multidimensional array.
I think my code can be better condensed :
...
2
votes
0
answers
54
views
editing the array I've included instead of editing the file of included array php
In order to reduce time complexity, instead of loading (and then dumping to use it for later) the whole file into an array (It would be O(n) with n=number of lines), I have saved it as array into a ...