title: Convert Array to JSON string php
body: <p>I have an array like this</p>
  <pre><code>$prebook=array(
               'sourceCity'=&gt;$_POST['source'], 
               'destinationCity'=&gt;$_POST['dest'],
               'doj'=&gt;$_POST['doj'],
               'routeScheduleId'=&gt;$_POST['routeid'],
                'boardingPoint'=&gt;array(
                    'id'=&gt;$id,
                    'location'=&gt;$location,
                    'time'=&gt;$time
                ),     
                'customerName'=&gt;$_POST['fname'],
                'customerLastName'=&gt;$_POST['lname'],
                'customerEmail'=&gt;$_POST['email'],
                'customerPhone'=&gt;$_POST['mobileno'],
                'emergencyPhNumber'=&gt;$_POST['emc-number'],
                'customerAddress'=&gt;$_POST['address'],
                'blockSeatPaxDetails'=&gt;array(array(
                    'age'=&gt;$_POST['age'][$key],
                    'name'=&gt;$value,
                    'seatNbr'=&gt;$_POST['seat-no'][$key],
                    'Sex'=&gt;$_POST['gender'.$no],
                    'fare'=&gt;$_POST['base-fare'][$key],
                    'totalFareWithTaxes'=&gt;$_POST['amount'][$key],
                    'ladiesSeat'=&gt;$ladies,
                    'lastName'=&gt;$_POST['plname'][$key],
                    'mobile'=&gt;$_POST['mobileno'],
                    'title'=&gt;'Mr',
                    'email'=&gt;$_POST['email'],
                    'idType'=&gt;$_POST['idtype'],
                    'idNumber'=&gt;$_POST['id-number'],
                    'nameOnId'=&gt;$value,
                    'primary'=&gt;true,
                    'ac'=&gt;$ac,
                    'sleeper'=&gt;$sleeper
           )),
                  'inventoryType'=&gt;$_POST['invtype']             
             )
  </code></pre>
  <p>From this i want to get Json string look like this</p>
  <pre><code>apiBlockTicketRequest:{&quot;sourceCity&quot;:&quot;Hyderabad&quot;,&quot;destinationCity&quot;:&quot;Bangalore&quot;,&quot;doj&quot;:&quot;2016-01-22&quot;,&quot;routeScheduleId&quot;:&quot;6717&quot;,&quot;boardingPoint&quot;:{&quot;id&quot;:&quot;2889&quot;,&quot;location&quot;:&quot;Mettuguda,Opp. Mettuguda Church&quot;,&quot;time&quot;:&quot;04:50PM&quot;},&quot;customerName&quot;:&quot;jj&quot;,&quot;customerLastName&quot;:&quot;jjj&quot;,&quot;customerEmail&quot;:&quot;shamonsha665@gmail.com&quot;,&quot;customerPhone&quot;:&quot;7779&quot;,&quot;emergencyPhNumber&quot;:&quot;7878&quot;,&quot;customerAddress&quot;:&quot;gjgj&quot;,&quot;blockSeatPaxDetails&quot;:[{&quot;age&quot;:&quot;22&quot;,&quot;name&quot;:&quot;hjhj&quot;,&quot;seatNbr&quot;:&quot;G4&quot;,&quot;Sex&quot;:&quot;F&quot;,&quot;fare&quot;:&quot;900&quot;,&quot;totalFareWithTaxes&quot;:&quot;945&quot;,&quot;ladiesSeat&quot;:false,&quot;lastName&quot;:&quot;hjhj&quot;,&quot;mobile&quot;:&quot;7779&quot;,&quot;title&quot;:&quot;Mr&quot;,&quot;email&quot;:&quot;shamonsha665@gmail.com&quot;,&quot;idType&quot;:&quot;Aadhar Card&quot;,&quot;idNumber&quot;:&quot;jkjk&quot;,&quot;nameOnId&quot;:&quot;hjhj&quot;,&quot;primary&quot;:true,&quot;ac&quot;:false,&quot;sleeper&quot;:false}],&quot;inventoryType&quot;:&quot;0&quot;}
  </code></pre>
  <p>Here is my code</p>
  <pre><code>$data =json_encode($prebook);
  $json='apiBlockTicketRequest:'.$data;
  echo $json;
  </code></pre>
  <p>But when i Validate the JSON string using <a href="https://jsonformatter.curiousconcept.com/" rel="nofollow noreferrer">this</a> I will get the following error</p>
  <blockquote>
  <p>Expecting object or array, not string.[Code 1, Structure 1]</p>
  <p>Error:Strings should be wrapped in double quotes.</p>
  </blockquote>