Use foreach loop to assign postdata variable

I wonder if I can use foreach to optimize my code and avoid mistakes.

I have to set variable like that from postdata:

$a2 = $postdata->a2;     $a3 = $postdata->a3;         $a4 = $postdata->a4; 

and so on…

I forgot one line, it cause trooble in my treatment.

I thought a code like that, but, I’m no sure it will works:

foreach($postdata as $key => $value) {               $"a2, a3, a4,..." = $postdata->"a2, a3, a4,..."; } 

Thanks for helping me 😉

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.