So I’m trying to create an open source file manager with php using ajax requests and, when i use json_encode my json response gets a close bracket for each array key. This is the code (PHP): and this is the result: and i need this result Answer You encode to quickly. Try this:
Tag: arrays
PHP send an array with subarray value(s) to a function along with its key
I have a associative array(shown below). I want to send $demographics[‘customer’] to a function and access both the key and value of the array. Actual: Expected: Answer If you just need to send a specific part of the array to the function, you can also use array_slice(). Like with the first element like this: Also refer to: https://www.php.net/manual/en/function.array-slice.php
Creating JSON Array out of PHP loop
in my current project I want to fill a bar chart with summed data for each day of a month. I get the required values from the database, but I can’t get the array created in the right format. So far, the individual values are just lined up and I can’t read them out in the JS. I have tried
Find all descendants in array
At first look it was a simple task, but when I tried to solve it I became confused. I have PHP array, where keys are top parent IDs, values are child IDs. Some child IDs have their own children. That children may have own children and so on. My goal is to get a new array, where all top parent
How to get class from a constant array?
I have about twenty different classes that are segregated in an assoc array similar to this: But now I want to do the array constant. I can make it using const VAL = array(); just fine. The problem lies in making new objects using those classes fails with Parse error: syntax error, unexpected ‘[‘, expecting ‘)’ error. I figured that
php can not get array value from an array
I have an array: And I would like to get the first value in the array: I have tried each of the following: array_values($_array)[0]; $data[0]; array_keys($data)[0]; But none of them work, and I instead get an empty string. I need to get the first element or key of the array. Answer you can use array_key_first(your_array) Get the first key of
Separate date to several intervals
I’ve got an array like the following : And another array : I would like to create a new $array3 that removes the intervals from $array2 in $array1 to give the following result : As you can see, in $array3 2 new entries were added to remove the interval used in $array2. I don’t know how can I tackle an
PHP OO – Associative array of object instances, resetting on each click
My first ever question on here as I’m completely stuck, so apologies if I leave out any key information – please let me know! I am creating a PHP Battleships game and trying to use full OO. I’m really close, however, an array for one of my classes does not hold any updates I make to it. First off, I
Group rows on one column and form nested subarray with other column
Here is the thing I trying deal with I have array which looks like this and have duplicates Result that I need to get is below . I did try different ways to do it but still can bring it to the finel result that have to come up any suggestion how to do it ? here is my best
How is it possible to fetch only the first item of the same element type inside an array php?
I have an array with different data in it for example like this how do I go about to only fetch the first “Laptop”, I was able to fetch them but they come both at the same time I used the $key as $value inside a foreach but it still returns both if I give it a condition to only