I have this json literal string
{
"properties_form_data": {
"user_id":"edhdh83883737364623",
"property_owner":"rammstein",
"property_name": "rockers",
"property_address":"hard metal",
"property_coordinates": true,
"property_type": true,
"property_country": true,
"property_district": true,
"property_region": "description",
"property_city": "description",
"property_profile": "description",
"checkin_time": "description",
"checkin_out_time": "description which is "afraid"",
"pets_allowed": false,
"age_restriction_for_checkin": true,
"property_images":{"property_s3_image_links":"1.jpg,2.jpg,3.jpg","date_updated":"95356373773"},
"property_amenities":{"together":true,"prospering":true,"touring_right_now":false},
"sorrounding_areas":[{
"album_id": "23883838dhhskk89968654s",
"album_name":"Rammstein",
"date_taken":"35356373773"
}],
"restaurants":[{
"album_id": "23883838dhhskk89968654s",
"album_name":"Rammstein",
"date_taken":"35356373773"
}],
"date_inserted":"hard metal",
"updated_on": true
}
}
I am getting some data from the client that i want to add to the string then encode it and store it away.I am receiving several data sets as arrays and i wanted to add that as well by looping and encoding the resulting json literal string
<?php
$no = '';
$h = rand(6,99999);
$newarr = array(6,9,8,0,7);
print_r($newarr);
for ($x = 0; $x <= 10; $x++) {
$no = '{
"album_id": "'.$x.'",
"album_name":"Rammstein",
"date_taken":"35356373773"
}';
}
$jl ='{
"properties_form_data": {
"user_id":"edhdh83883737364623",
"property_owner":"rammstein",
"property_name": "'.$h.'",
"property_address":"hard metal",
"property_coordinates": true,
"property_type": true,
"property_country": true,
"property_district": true,
"property_region": "description",
"property_city": "description",
"property_profile": "description",
"checkin_time": "description",
"checkin_out_time": "description which is "afraid"",
"pets_allowed": false,
"age_restriction_for_checkin": true,
"property_images":{"property_s3_image_links":"1.jpg,2.jpg,3.jpg","date_updated":"95356373773"},
"property_amenities":{"together":true,"prospering":true,"touring_right_now":false},
"sorrounding_areas":['.$no.'],
"restaurants":[{
"album_id": "23883838dhhskk89968654s",
"album_name":"Rammstein",
"date_taken":"35356373773"
}],
"date_inserted":"hard metal",
"updated_on": true
}
}';
echo '<pre>';
echo $jl;
echo '</pre>';
?>
php complains that i can't use the for loop from inside the json literal which is a problem because i have several arrays i want to add. How can i add the array data in the json literal string?.
echoinside an assignment (illegal) and you're trying to use+to concatenate (mixing up JS and PHP syntax).