0

I have an array in PHP that contains several arrays, like below.

I want to be able to grab the values that comes from one brand at the time. For example: grab all sizes, all materials and all colors that has the brand number 55. Have looked on tutorials on how to get values from multidimensional arrays but I just can't get it to work.

Array (

[0] => Array ( [size_1] => 7 [brand] => 45 )

[1] => Array ( [size_1] => 13 [brand] => 55 )

[2] => Array ( [material_1] => 7 [brand] => 45 )

[3] => Array ( [material_1] => 17 [brand] => 55 )

[4] => Array ( [material_2] => 15 [brand] => 45 )

[5] => Array ( [material_3] => 16 [brand] => 45 )

[6] => Array ( [material_4] => 8 [brand] => 45 )

[7] => Array ( [material_5] => 9 [brand] => 45 )

[8] => Array ( [material_5] => 11 [brand] => 86 )

[9] => Array ( [color_1] => 1093 [brand] => 55 )

[10] => Array ( [color_1] => 3064 [brand] => 54 )

[11] => Array ( [color_2] => 1687 [brand] => 55 )

[12] => Array ( [color_3] => 2297 [brand] => 55 )

[13] => Array ( [color_4] => 1280 [brand] => 55 )

[14] => Array ( [color_5] => 2822 [brand] => 55 )

) 
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Peter Karlsson
  • 403
  • 5
  • 19
  • Have you used a `foreach` before – RiggsFolly Jan 26 '17 at 10:12
  • 1
    Maybe you should look at how you create this array and create it in the format you want with only that data you want. Does this come from a query against the database – RiggsFolly Jan 26 '17 at 10:13
  • A combination of array_column() and array_filter() perhaps? – Mark Baker Jan 26 '17 at 10:14
  • Iterate thru the array values while checking for the particular value you want then when you get it, identify its index at that point and use this index to get the size, material and color at that index. – Joseph Jan 26 '17 at 10:22

0 Answers0