Skip to content

Tag: arrays

Convert SQL results into PHP array

I’m fairly new to PHP and I’ve been looking around and can’t seem to find the specific answer I’m looking for. I want to make a SQL query, such as this: Basically I want to take the entire contents of the result and create an array that I can access in a similar fashion as the row. For…

Implode array with array of glue strings

I have a awkward need but I need to interleave an array with another array before imploding the result. I guess my better option would be less talk more example Array number one Array number two I need to produce My question is can I do that with an implode or I must build my own function? Answer Adapted from

PHP rotate matrix counter-clockwise

I am solving a larger problem and at one step I need to rotate a 2D array counter-clockwise. So if I have this matrix: After the rotation it will be: I have found a solution to rotate it clockwise: The thing is that this has to work even when a is uni-dimensional or has only one element. So, 1 2

php for loop from array stops after 3 loops

I have an array that looks like this. I want to loop through array in the first key of [2] and echo all the values. this works, but stops after three loops and the output looks like this: I am expecting — hoping for this: I don’t understand why it is stopping. thanks. Answer Your problem lies here…

Sort array and keep values of keys

I have an array that looks like this: and I would like to sort the teams by the number of points each team has. I have tried this: But that approach overrides the keys containing the teamnames and returns: Is there any way to sort the array without overwriting the teamnames as the array keys? Answer Use the u…