Skip to content
Advertisement

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 example, if

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: You are

PHP retrieving array values using dash arrow “->”

I’ve been using PHP quite a while now, but never been an advanced programmer. I feel like this is dumb question but never understood why some array values can be retrieved using different methods: This: rather than normal: The standard $array[‘value’] always works, but the one using the -> method doesn’t at times. Why is that? Here’s an example. I

PHP array – explode some comma separated elements into new items

How can I take an array with individual strings but also comma separated strings and explode the comma separated items into individual items? For instance: $product_array[] returns: How can I split item 3 into individual items 3, 4 and 5 so that $product_array returns: Answer Here is fast solution 🙂 if there is comma it will explode it before adding

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 uasort function,

Advertisement