Skip to content
Advertisement

Replace every string in multidimensional array if conditions matched

Ok so I have an array look like this,

JavaScript

What I want to do is, in any element of this multidimensional array I want to replace any string that have a . with removing everything after .

So the new array should look like this,

JavaScript

I have tried doing this,

JavaScript

I’m getting $value[0] as order_date but can’t figure out how to assign it to $filter array without affecting other values in array;

Advertisement

Answer

The $value variable is not linked with the original array in the foreach loop. You can make a reference to the original array by using ampersand “&”

JavaScript

Or you can use old school key nesting

JavaScript

Please take a look here https://stackoverflow.com/a/10121508/9429832

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement