- memory_get_peak_usage: documentation ( source)
- json_decode: documentation ( source)
- microtime: documentation ( source)
<?php
$start = microtime(true);
$json_1 = '[{"MobileNo":"123"},{"MobileNo":"456"}]';
$json_2 = '[{"MobileNo":"07123456701"}]';
$multiple = json_decode($json_1, true);
$doc = new DOMDocument();
$doc->formatOutput = true;
$root = $doc->createElement("Msg");
$doc->appendChild($root);
$root->appendChild($doc->createElement("JobId", 77));
foreach ($multiple as $mobile) {
$result = $doc->createElement("SubmitResult");
$result->appendChild($doc->createElement("MobileNo", $mobile["MobileNo"]));
$result->appendChild($doc->createElement("StatusId", 0));
$result->appendChild($doc->createElement("StatusText", "Success: Message submitted successfully"));
$root->appendChild($result);
}
$doc->saveXML();
$stop = microtime(true);
$seconds = $stop - $start;
echo "Start: " . $start . PHP_EOL;
echo "Stop: " . $stop . PHP_EOL;
echo "Seconds: " . $seconds . PHP_EOL;
echo "Memory peak: " . memory_get_peak_usage() / 1048576 . 'MB' . PHP_EOL;