0

we are generating php variable name directly linked with mysql rows output. here it is

now we have dynamic variable and we are doing base64 encoding of images

     ${'attachment_base64'.$row['id']} = base64_encode(file_get_contents($some_url));

now we want to pass this dynamically generated variable in while loop

     $image_part .= 'array(
              "name" => "'.$name.'",
              "data" => "$attachment_base64"
        ),';

but we are unable to pass dybanic name in data.

this part should be like this

       "data" => "$attachment_base641556588"

where 1556588 was dynamic id from database.

we cant use '.$row['id'].' as it will just append the data to base64 encoded data we want dynamic variable name to pass here

want to pass dynamic name in my array data part otherwise when i use this data after loop same image is passed in data part

generating this type of array from while loop data

     array(
              "name" => "ggggf",
              "data" => "$attachment_base64",
        ),
        array(
              "name" => "6800164880433",
              "data" => "$attachment_base64",
        ),
10
  • I don't understand the question. Commented Aug 23, 2019 at 16:46
  • Why do you have quotes around the call to array()? Commented Aug 23, 2019 at 16:47
  • want to pass dynamic name in my array data part otherwise when i use this data after loop same image is passed in data part Commented Aug 23, 2019 at 16:48
  • @Barmar generating this type of array from while data array( "name" => "ggggf", "data" => "$attachment_base64", ), array( "name" => "6800164880433", "data" => "$attachment_base64", ), Commented Aug 23, 2019 at 16:51
  • 1
    Why are you concatenating strings instead of just pushing onto an array? Commented Aug 23, 2019 at 16:53

1 Answer 1

2

Concatenate $row['id'] after the variable name prefix.

     $image_part .= 'array(
              "name" => "'.$name.'",
              "data" => "$attachment_base64'.$row['id'].'"
        ),';

But I strongly suggest that you change from dynamic variable names to associative arrays.

Sign up to request clarification or add additional context in comments.

1 Comment

i am idiot no 1. i have tested same thing but was writing some other data and thinking it was not working, it works thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.