Could you point a way to eliminate an array unexpected element?
Hi Experts
Could you point a way to eliminate an array unexpected element?
Accordingly to this picture (hard to see since I had to take a photo, the copy/ paste isn't allowed from the prodution server):
The 4th element (I don't know the reason appear like it:
That is causing an error.
How to eliminate it from the array?
Thanks in advance.
PHP
Last Comment
Eduardo Fuerte
8/22/2022 - Mon
Ray Paseur
You can use unset() to remove an element from an array, but we would have to be able to read the array key to tell you the exact statement.
If the key is "foo" and the array is $arr, you would use unset($arr['foo']);
Eduardo Fuerte
ASKER
Hi Ray
Really, I tryed before the way you pointed but since the array index is so weird and I can't be sure it's a constant value, I decided to reconstruct the array by using only the correct values, like:
$dados [x] = $params[x];$dados [y] = $params[y];..$dados [n] = $params[n];//Don't considering $params [------7e1190133] =>// So, since $dados has only good values$params = $dados;
Your solutions is good if the index is always [------7e119013]
Since I do't know from where tjis index comes, I prefer to reconstruct the array...
Ray Paseur
Well, with most things like this, the devil is in the details. Can you provide us more examples of the "bad" index? It would seem possible to write a regular expression that could eliminate any of a set of possible bad indexes if we could discern the "rules" about the bad index.
You can rebuild the array, and that may get you to the end of the problem today, but it's a potentially brittle solution. For example, does the code that generates this array get called anywhere else in the system? If so, those parts of the system may need to be changed, too. The problem could have a lot of tentacles, like an octopus.
The bigger question, of course, is where did this get injected. And how did the subsystem pass unit tests but fail in the deployed application?
If the key is "foo" and the array is $arr, you would use unset($arr['foo']);