API3
frankebailey at February 27th, 2018 13:29 — #1
Hi folks, I'm new here. Is there a more logical way to grab the "company fields" data and assign them to local variables than doing a foreach on the array and testing against a pre-set number of fields with a switch statement? I can't help but feel I'm missing some more straightforward way to do it. The fields have spaces in the names and don't match the database field names so there's also that consideration.
johnmag at February 28th, 2018 09:10 — #2
Hi there @FrankEBailey
Welcome and thanks for getting in touch.
So just to be sure I'm clear on what you are trying to do.
You are fetching the company_fields
and iterating over the received array and assigning each of them to local variables within your PHP app and you are wondering if there is a more efficient way to assign the data to the local variables rather than just iterating over the array?
You say that you have a "pre-set number of fields" does this mean that in your program you need to know already which fields you will be passed from the API? would it be better to assign the variables dynamically from the array then you don't need to change your code when new fields are added to the company?
OR
are you using a pre-set number of fields because you only want certain fields and want to ignore all others even if new ones are added?
Just looking at PHP docs, something like extract could help you do this dynamically.
Let me know how this works for you.
Kind Regards,
John
Powered by Discourse, best viewed with JavaScript enabled