php - Problems with nested array after using unset -


i have dynamically built nested array need drop 1 or more indexes.

having scoured php information pages, found using

unset($quotes_array[0]['methods'][3]); 

would remove last set of data in array.

but, if try use

unset($quotes_array[0]['methods'][0]); 

or other set apart last, messes output generated array.

for instance, if had a,b,c,d: can remove d without issue, if try remove a, blank radio button followed b,c, d missing when array data processed.

i assuming need reindex array, every attempt i've made far has failed give required results, because i'm reindexing $quotes_array, whereas data need reindex within 'methods' indices.

is there way fix issue?

unsetting first element easy if use array_shift. array_shift pop first element off , reindex array you.

array_shift($quotes_array[0]['methods']); 

if need unset something in middle (such [ 2 ] out of [ 3 ]) use array_values. first unset element want remove, reindex them array_values.

unset($quotes_array[0]['methods'][2]); array_values($quotes_array[0]['methods']); 

if wanted remove last element of array use array_pop. array_pop pop last element off array. there no need reindex in situation.

array_pop($quotes_array[0]['methods']); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -