In the following code, I'm trying to create an array or a string based on if type is true or false
. If type
were true
, then i need to create an array else
I need to keep things as a string. I was trying as below, but it does not seem to work. Can you help?
<?php
$type = True;
if($type){
$body = "body['body']"; //Start an array
} else {
$body = 'body'; //Just a string
}
$body = 'Hello'; //$body = the value from up there
print_r($body);
?>
Expected Results:
If type = true //Array
print_r($body);
Array ([body] => Hello)
If type = false //String
print_r($body);
Hello
Edit The content for the array or string is outside the if and comes after it. I need to start as a array or sting based on the type.