0
When using the json Decode function on a json, I’m having a problem. When the numbering is perfectly in order(0,1,2,3...) it is classified as arra:
[2016-08-01] => Array
(
[0] => 07:00:00
[1] => 07:20:00
[2] => 07:40:00
[3] => 08:00:00
[4] => 08:20:00
[5] => 08:40:00
[6] => 09:00:00
[7] => 09:20:00
[8] => 09:40:00
[9] => 10:00:00
[10] => 10:20:00
[11] => 10:40:00
[12] => 11:00:00
)
However, when I need to remove some schedules it automatically turns into object (I removed the element of Indice 9 and 10)
[2016-07-25] => stdClass Object
(
[0] => 07:00:00
[1] => 07:20:00
[2] => 07:40:00
[3] => 08:00:00
[4] => 08:20:00
[5] => 08:40:00
[6] => 09:00:00
[7] => 09:20:00
[8] => 09:40:00
[11] => 10:40:00
[12] => 11:00:00
)
I would like to know how to prevent this from happening, or if not, pass all my data to object, or all data to array.
How are you making that withdrawal?
– Fleuquer Lima
you pass the second argument as
true
at all times?– rray
Exact should put the second argument of
json_decode
astrue
if you want to transform into array instead of obj– Miguel
I have a function that checks the available schedules of a professional. I make a series of checks to see if you have exceptions, filled out schedules, blockades. Then, when arriving at the end of the function, my initial array has undergone a lot of changes. Basically I took an item from that array with unset();
– Vinicius Maia
Perfect. The true parameter worked. Thank you.
– Vinicius Maia
So you’re doing a cast there on these validations.
– rray
Add the JSON format and how you are capturing and removing the data in the question, otherwise you cannot answer objectively. It’s a very simple problem, but you need this data to be consistent with the answers to the question.
– Bacco