Jump to content

Remove subarray


Jonob

Recommended Posts

I have a multi-dimensional array. Lets assume its something like:

 

[0]
  [0] -> 'Green'
  [1] -> 'Soccer'
  [2] -> 'Oranges'
[1]
  [0] -> 'Blue'
  [1] -> 'Rugby'
  [2] -> 'Apples'

 

I want to remove the [2] index frome each sub-array, so that I land up with:

 

[0]
  [0] -> 'Green'
  [1] -> 'Soccer'
[1]
  [0] -> 'Blue'
  [1] -> 'Rugby'

 

I can do this easily by looping through ...but is there an easier/faster way?

Link to comment
https://forums.phpfreaks.com/topic/193820-remove-subarray/
Share on other sites

array_diff_key wont work like that. You would need to build an array exactly the opposite of what you want then diff it against the original array. ie

array(

array(2=>'')

array(2=>'')

etc for each sub array

 

The fastest and easiest way is the foreach you have been previously shown.

 

 

HTH

Teamatomic

Link to comment
https://forums.phpfreaks.com/topic/193820-remove-subarray/#findComment-1020249
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.