ngrmm Posted August 1, 2023 Share Posted August 1, 2023 (edited) Which syntax is need for this? // field names: // field_1 // field_2 // field_3 // … for ($i = 1; $i <= 40; $i++) { if($page->field_{$i} == 'test') { // this does not work // do stuff } } Edited August 1, 2023 by ngrmm solved Link to comment Share on other sites More sharing options...
BillH Posted August 1, 2023 Share Posted August 1, 2023 I think you have to do it like this: for ($i = 1; $i <= 40; $i++) { $fieldname = "field_$i"; if($page->$fieldname == 'test') { // do stuff } } 2 Link to comment Share on other sites More sharing options...
ngrmm Posted August 1, 2023 Author Share Posted August 1, 2023 thanks @BillH Link to comment Share on other sites More sharing options...
BillH Posted August 1, 2023 Share Posted August 1, 2023 It occurs to me that if you want a single expression you could also use: if($page->get("field_$i") == 'test') { ... 1 Link to comment Share on other sites More sharing options...
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