Tyssen Posted January 6, 2023 Posted January 6, 2023 I'm trying to do this: $img_w_0 = 312; $img_w_1 = 485; $img_w_2 = 380; foreach ($page->images as $i=>$image): $contentImages .= 'Width = '. ${'img_w_'.$i}; which produces Width = Width = Width = and no value. If I instead do this: $images = array( '0.jpg', '1.jpg', '2.jpg' ); foreach ($images as $i=>$image): then I get the correct values printed out, i.e. Width = 312, Width = 485, Width = 380. Why does the index not work for the page images array?
BitPoet Posted January 6, 2023 Posted January 6, 2023 6 hours ago, Tyssen said: Why does the index not work for the page images array? That's because it's not a regular array but a PageImages object. If you inspect $i in your first example, you'll see that it contains the image filename, not a numeric index. To get a plain array without the filenames as keys, use its inherited getValues() method. foreach ($page->images->getValues() as $i => $image): 5 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now