Assign value dynamically to variable by String Concatenation, by assigning dynamic string in loop and call the method dynamically.

Once I have need to assign a dynamically string concatenation variable value in loop

I have 3 array and in string last of digit is related to my array name so I used two logic

One for string subpart and another for assigning dynamic value.

My variable are

$Str1 = array();

$Str2  = array();

$Str3  = array();

I have checkbox in frontend form

And its has value are searchsimple1 searchadvance2 and searchprice3. so I have need to call method dynamically and assign the value dynamically to Str Pairs.

Frontend checkbox name is search[].

foreach($_post[search] as $value)

//call the method as per as value so substr for method name
 $value1 = substr($value,0,strlen($value)-1);

//assign last digit of variable to str_concate so it can assign dynamically Str1 ,etc..
 $str_concator = substr($value,strlen($value1));

//assigning value to Str and calling function dynamically
 ${"search$search_concator"} = $value1($post);


I hope this will help you lot thanks in advance

Speak Your Mind

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: