Link to home
Start Free TrialLog in
Avatar of Eduardo Fuerte
Eduardo FuerteFlag 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):
User generated image
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.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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']);
Avatar of 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...
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?
Avatar of Julian Hansen
Can we see where the data is coming from?

What is the source of the data?
Hi

I'm still checking the code from where this array element came from...
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Since I had not found the cause of this  array's symptom I think the remedy is ok.

Thanks!