0

I am currently populating an associative array like this:

$plates_data['data'][] = array("drilldown"=>$sImageUrl, "type"=>$Type, "job_no"=>$Job_No, "customer"=>$Customer);

I'd like to be able to do something like this:

$myvar = '"drilldown"=>$sImageUrl, "type"=>$Type, "job_no"=>$Job_No, "customer"=>$Customer';

 $plates_data['data'][] = array($myvar);

This doesn't work, can someone tell me what i'm doing wrong?

3
  • What are you trying to accomplish? In the scenario provided your second option is just extra lines and wouldn't result in shorter code Commented Jul 15, 2014 at 0:49
  • you are adding an array that contains a single entry which is a string to the next element in the data element of the $plates_data array. Commented Jul 15, 2014 at 0:49
  • variables inside single quotes will not be expanded. also not sure what you are trying to accomplish. Commented Jul 15, 2014 at 0:49

1 Answer 1

2

You can use it like this

$array_holder = array("drilldown"=>$sImageUrl, "type"=>$Type, "job_no"=>$Job_No,"customer"=>$Customer);

 $plates_data['data'][] = $array_holder;
Sign up to request clarification or add additional context in comments.

2 Comments

This works, thanks so much!. I have to use the array more than once in a script. If I had to change entries, I had to do it twice, now I can do it once.
You can directly use it like this $plates_data['data'][] = array("drilldown"=>$sImageUrl, "type"=>$Type, "job_no"=>$Job_No,"customer"=>$Customer);

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.