I have the following array:
<?php
$bridal_artists = array(
array(
'id' => 1,
'name' => 'Artist 01',
'section' => array( 'engagement', 'wedding' ),
'featured_img' => array( 'engagement' => 0, 'wedding' => 2 ),
'images' => array(
array( 'artist01-01.jpg', 'Classic Anne Engagement Ring' ),
array( 'artist01-02.jpg', 'Wonky Diamond Band, 0.09ctw diamonds' ),
array( 'artist01-03.jpg', 'Two Row Pavé Band, 0.24ctw diamonds' ),
array( 'artist01-04.jpg', 'Narrow Pavé Diamond Band, 0.36ctw diamonds' ),
array( 'artist01-05.jpg', 'Leslie Engagement Ring' ),
array( 'artist01-06.jpg', 'Four Claw Pavé Diamond Engagement Ring' ),
array( 'artist01-07.jpg', 'Louisa Engagement Ring' ),
array( 'artist01-08.jpg', 'Original Halo Engagement Ring' ),
array( 'artist01-09.jpg', 'Bark Textured Solitaire Engagement Ring' ),
array( 'artist01-10.jpg', 'Alexa Engagement Ring' ),
array( 'artist01-11.jpg', 'Dancing Diamond Engagement Ring' ),
array( 'artist01-12.jpg', 'Trinity Engagement Ring' ),
array( 'artist01-13.jpg', 'Scalloped Engagement Ring' ),
array( 'artist01-14.jpg', 'Cushion Double Halo Engagement Ring' ),
array( 'artist01-15.jpg', 'Triple Illusion Cushion Engagement Ring' ),
array( 'artist01-16.jpg', 'Marion Engagement Ring' ),
),
),
array(
'id' => 2,
'name' => 'Artist 2',
'section' => array( 'engagement', 'wedding' ),
'featured_img' => array( 'engagement' => 0, 'wedding' => 2 ),
'images' => array(
array( 'artist02-01.jpg', 'Bamboo Damascus Steel Band' ),
array( 'artist02-02.jpg', 'Infinity Damascus Steel Band yellow gold liner and rails' ),
array( 'artist02-03.jpg', 'Vortex Damascus Steel Band white gold liner and rails' ),
array( 'artist02-04.jpg', 'Wood Grain Damascus Steel Band' ),
array( 'artist02-05.jpg', 'Hailey Engagement Ring damascus steel and gold with 0.25ct diamond' ),
array( 'artist02-06.jpg', 'Beech Mokume-gane Band 18k yellow gold, palladium, sterling silver' ),
array( 'artist02-07.jpg', 'Arcturus Meteorite Band, white gold, meteorite' ),
array( 'artist02-08.jpg', 'Arcturus Meteorite Band, yellow gold, meteorite' ),
array( 'artist02-09.jpg', 'Sirius Meteorite Band, meteorite, white gold liner and rails' ),
array( 'artist02-10.jpg', 'Sirius Meteorite Band, meteorite, yellow gold liner and rails' ),
),
),
array(
'id' => 3,
'name' => 'Artist 3',
'section' => array( 'wedding' ),
'featured_img' => array( 'wedding' => 1 ),
'images' => array(
array( 'artist03-01.jpg', 'ACE000 Mokume-gane band, 18k yellow gold, 14k white and rose gold, sterling silver, etched finish' ),
array( 'artist03-02.jpg', 'ACE000 Mokume-gane band, 18k yellow gold, 14k white and rose gold, sterling silver, smooth finish' ),
array( 'artist03-03.jpg', 'ZCE000 Mokume-gane band, sterling silver, palladium, tight wood-grain etched finish' ),
array( 'artist03-04.jpg', 'ACN000 Mokume-gane band, 18k yellow gold, 14k white and rose gold, sterling silver, smooth finish' ),
array( 'artist03-05.jpg', 'HCN000 Mokume-gane band, 14k white and rose gold, sterling silver, smooth finish' ),
array( 'artist03-06.jpg', 'CCE000 Mokume-gane band, 14k white gold, palladium, sterling silver, etched finish' ),
),
),
array(
'id' => 4,
'name' => 'Artist 4',
'section' => array( 'engagement', 'wedding' ),
'featured_img' => array( 'engagement' => 4, 'wedding' => 1 ),
'images' => array(
array( 'artist04-01.jpg', 'Cava Engagement Ring' ),
array( 'artist04-02.jpg', 'Cava Ch Rd Band, 0.14ctw diamonds' ),
array( 'artist04-03.jpg', 'Iris Pavé Engagement Ring, 0.19ctw diamond sides' ),
array( 'artist04-04.jpg', 'Perth Pavé Engagement Ring and Band, 0.24ctw diamond sides' ),
array( 'artist04-05.jpg', 'Poppy Engagement Ring, 0.22ctw diamond sides' ),
array( 'artist04-06.jpg', 'Poppy Pavé Band, 0.17ctw sides' ),
array( 'artist04-07.jpg', 'Sanday Engagement Ring' ),
array( 'artist04-08.jpg', 'Scotasay Engagement Ring, 0.55ctw diamond sides' ),
),
),
);
?>
The array holds the relevant data per each artist. Multidimensional, as seen above. I used a foreach loop to iterate through all of them then a second one to loop through the main keys. However, when I try to use a key name, I get "undefined offset." I tried the numeric offset and that gives me "illegal string offset" instead.
<?php foreach ($bridal_artists as $artist): ?>
<?php foreach ($artist as $key => $value): ?>
<?php if($key[2][0] == $cat || $value[2][1] == $cat): ?>
rest of logic here
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
Some additional information: the array is contained in its own phtml file and included in the phtml files where it's necessary. I'm using PHP 7.2.24 and this is for a Magento 2 site. If there is a Magento 2 specific solution, that would be great.
Not sure what I've done wrong and why this isn't working. I know something's wrong, else I wouldn't get an error. Am I structuring the loops incorrectly? Using the keys wrong? Would a switch be a better idea here?