I have the following array: I’d like to rotate the elements of this array with the first key being the tomorrow. Let’s say today was Wednesday, I’d want my array to look like this: I already have the weekday available (e.g. a string ‘thursday’). It gets passed into the function that I’m working with. Answer If you convert the day
Tag: arrays
How to force Doctrine to update array type fields?
I have a Doctrine entity with array type field: /** * @ORMTable() */ class MyEntity { (…) /** * @var array $items * * @ORMColumn( type=”array” ) */ private $…
Get most recent date from an array of dates in “Y-m-d H:i:s” format
I have the array of dates in Y-m-d H:i:s format like: I would like to know the most recent date. In other words, today is June 13th 2012, which datetime is closest to today’s date? From my sample array, I am expecting 2012-06-11 08:30:49. How can I do that? Answer Do a loop, convert the values to date, and store
How can i pass a single additional argument to array_map callback in PHP?
How can i pass a single additional argument to array_map callback? In my example i’d like to pass $smsPattern (as a second argument, after current element in $featureNames) to the function array_map …
explode an array of delimited strings into two arrays
I have the following array: that I need to split into two arrays using “-” as delimiter: and Is there anything like array_explode that does what I want? or a combination of php array functions? I’d like to do this without going through my own for/each loop, if possible, or at least minimize having to reinvent the wheel when something
Check if all values in array are the same
I need to check if all values in an array equal the same thing. For example: If every value in the array equals ‘true’ then I want to echo ‘all true’. If any value in the array equals ‘false’ then I want to echo ‘some false’ Any idea on how I can do this? Answer All values equal the test
Storing application permissions in a database
I’m developing an application for our company that eventually will have lots of ways of restricting users to particular sections/modules. While the application is still small, I’d like to move to a new method of storing permissions that, as the application grows, will remain easy to maintain and query. Currently in our MySQL database we have a table called “user”
Best way to clear a PHP array’s values
Which is more efficient for clearing all values in an array? The first one would require me to use that function each time in the loop of the second example. foreach ($array as $i => $value) { …
php multidimensional array get values
This is my array in php $hotels Array ( [0] => Array ( [hotel_name] => Name [info] => info [rooms] => Array ( [0] => …
Remove all array elements except what I want?
I have controller that takes post parameters from HTML form, it will then send them to model that will insert the array into Cassandra database. It is SQLInjection proof, because it’s NoSQL, however what I’m afraid is that user can just simulate 100k post parameters or just add some that I don’t need and it will be inserted into database.