Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove array item by index (not numeric index but string) [duplicate]

I have the following JavaScript array :

[#ad: Array[0]]
    #ad: Array[0]
        #image_upload: Array[0]
            13b7afb8b11644e17569bd2efb571b10: "This is an error"
            69553926a7783c27f7c18eff55cbd429: "Yet another error"
            d3042d83b81e01d5c2b8bbe507f0d709: "Another error"
    Array[0]
        #image_url: Array[0]
            2b4a9847e26368312704b8849de9247a: "URL error"

This is the array representation in my browser console.

Unfortunatelly I cannot find a way to remove the elements of the $errors['#ad']['#image_upload'] based on the md5 keys.

In example, let's say I like to remove the message "Yet another error" by using the corresponding md5 key 69553926a7783c27f7c18eff55cbd429.

I have try the method indexOf but this is not the correct one, as return the index of the value in the array. What I need is the opposite, I need to remove the value directly by using the index of the value.

How can I perform this task ? Any idea ?

like image 919
KodeFor.Me Avatar asked Oct 08 '14 07:10

KodeFor.Me


1 Answers

The delete operator should work here:

delete $errors['#ad']['#image_upload']['69553926a7783c27f7c18eff55cbd429']
like image 101
Scimonster Avatar answered Oct 21 '22 00:10

Scimonster