I have this chunk of code, one sample is $dispatch='TC_12':
foreach($this->dispatch as $dispatch){
$data['$dispatch'] = $this->genericQuery($dispatch, '1');
}
$this->dispatch is an array of dispatch tables. However, I wrote the method genericQuery() to generate dynamically generated queries. Everything works fine, except when I analyse the JSON object returned I saw:
`"$dispatch":["Hello world"]}`
However I would like to see "TC_12":["Hello world"].
How can I obtain that result? I thought the string would get replaced at $data['$dispatch'].
Variables only get replaced in double-quoted strings. Dollar signs are treated as literals in single-quoted strings. (See http://www.php.net/manual/en/language.types.string.php.) In this case, though, there’s no need for quotes at all. Try this: