Avatar of Eduardo Fuerte
Eduardo Fuerte
Flag for Brazil asked on

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):
img001
The 4th element (I don't know the reason appear  like it:

[------7e1190133] =>

Open in new window

That is causing an error.
How to eliminate it from the array?

Thanks in advance.
PHP

Avatar of undefined
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;

Open in new window


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?
Your help has saved me hundreds of hours of internet surfing.
fblack61
Julian Hansen

Can we see where the data is coming from?

What is the source of the data?
Eduardo Fuerte

ASKER
Hi

I'm still checking the code from where this array element came from...
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
skullnobrains

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Eduardo Fuerte

ASKER
Since I had not found the cause of this  array's symptom I think the remedy is ok.

Thanks!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.