'How I can use Object format content in PHP
I am creating a portal where I can check whether a user is satisfying a condition or not. If the user satisfies the condition then the content is visible, otherwise it stays hidden.
I have one form page where I take these conditions from the admin and store it in the database in string form. Basically, it is JSON.
That JSON stored in the database looks like this
[
{"parameter":"age","condition":"age >= 39 && age <= 149"},
{"parameter":"gender","array": ["Male","Female","other"],"condition":"genderArray.includes(gender)"},
{"parameter":"state","array":["Jammu and Kashmir","Arunachal Pradesh","Daman and Diu (UT)"],"condition":"stateArray.includes(state)"},
{"parameter":"category","array": ["ST","OBC","SC"],"condition":"categoryArray.includes(category)"}
]
Now I am facing a problem: How can I frame this in manner to be able to check if the user is eligible or not?
Supposing there is user data already store in the variable like: age, gender, state, category...
Is it possible to use the condition from the JSON which is stored in database and check if condition applies to the user?
Solution 1:[1]
Make use of the “json_decode()” function to convert the JSON data into php object. Then you will be able to use any object data you wish.
Showing the part of your php code you’re having issue with may ease understanding your problem
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | yuxufabio |
