Results: 1024
12<img src="https://sibrdzne.ge/d1_images/logo.png" alt="Logo" class="image">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam a nunc at ante eleifend tempor. In vel ullamcorper tellus, et vulputate metus. Integer pulvinar, ipsum in efficitur fringilla, dolor lacus sollicitudin tortor, vitae tincidunt nunc elit id ipsum. Proin laoreet, est ut placerat sollicitudin, lectus mi pellentesque est, vel accumsan velit sem id felis.
<p>New P</p>
$password = "your_password";
Hash the password with cost factor
9
$start9 = microtime(true);
$hash9 = password_hash($password, PASSWORD_BCRYPT, ['cost' => 9]);
$end9 = microtime(true);
$executionTime9 = $end9 - $start9;
Hash the password with cost factor
10
$start10 = microtime(true);
$hash10 = password_hash($password, PASSWORD_BCRYPT, ['cost' => 10]);
$end10 = microtime(true);
$executionTime10 = $end10 - $start10;
Calculate the speedup factor
$speedupFactor = $executionTime10 / $executionTime9;

// Display the hashed passwords, execution times, and speedup factor
echo "Hashed password with cost 9: " . $hash9 . "\n";
echo "Execution time with cost 9: " . $executionTime9 . " seconds\n\n";
echo "Hashed password with cost 10: " . $hash10 . "\n";
echo "Execution time with cost 10: " . $executionTime10 . " seconds\n\n";
echo "Speedup factor (9 vs 10): " . $speedupFactor . " times faster\n";
$start = microtime(true);

sleep(3);
// Your script code here

$end = microtime(true);
$latency = round($end - $start, 2);
echo "Script execution time: " . $latency . " seconds";
The
round
function will round the result to
2
decimals
Array to XML with SimpleXMLElement CODE
Built-in class
SimpleXMLElement
converts array to XML
$test_array = array (
  'bla' => 'blub',
  'foo' => 'bar',
  'another_array' => array (
    'stack' => 'overflow',
  ),
);

$xml = new SimpleXMLElement('<rootTag/>');
to_xml($xml, $test_array);
print $xml->asXML();

function to_xml(SimpleXMLElement $object, array $data)
{   
    foreach ($data as $key => $value) {
        if (is_array($value)) {
            $new_object = $object->addChild($key);
            to_xml($new_object, $value);
        } else {
            // if the key is an integer, it needs text with it to actually work.
            if ($key != 0 && $key == (int) $key) {
                $key = "key_$key";
            }

            $object->addChild($key, $value);
        }   
    }   
}
Get the first and last days of the current month
Gets the first and last days of the current month and passes it to the request using
start_date
and
end_date
variables. The following script should be located in
Pre-request Script
let date = new Date();
let year = date.getFullYear()
let month = ("0" + (date.getMonth() + 1)).slice(-2)
let start_date = year+'-'+month+'-01';
let days = new Date(year, month, 0).getDate()
let end_date = year+'-'+month+'-'+days;

pm.collectionVariables.set("start_date", start_date);
pm.collectionVariables.set("end_date", end_date);
Get URL of the request
https://httpbin.org/get?start_date={{start_date}}&end_date={{end_date}}
Postman Snippets
Get variables
pm.environment.get("variable_key");
pm.globals.get("variable_key");
pm.variables.get("variable_key");
pm.collectionVariables.get("variable_key");
Set variables
pm.environment.set("variable_key", "variable_value");
pm.globals.set("variable_key", "variable_value");
pm.collectionVariables.set("variable_key", "variable_value");
Unset variables
pm.environment.unset("variable_key");
pm.globals.unset("variable_key");
pm.collectionVariables.unset("variable_key");
Send a request
pm.sendRequest("https://postman-echo.com/get", function (err, response) {
    console.log(response.json());
});
Status code: Code is 200
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});
Response body: Contains string
pm.test("Body matches string", function () {
    pm.expect(pm.response.text()).to.include("string_you_want_to_search");
});
Response body: JSON value check
pm.test("Your test name", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.value).to.eql(100);
});
Response body: is equal to a string
pm.test("Body is correct", function () {
    pm.response.to.have.body("response_body_string");
});
Response headers: Content-Type header check
pm.test("Content-Type is present", function () {
    pm.response.to.have.header("Content-Type");
});
Response time is less than 200ms
pm.test("Response time is less than 200ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(200);
});
Status code: Successful POST request
pm.test("Successful POST request", function () {
    pm.expect(pm.response.code).to.be.oneOf([201, 202]);
});
Status code: Code name has string
pm.test("Status code name has string", function () {
    pm.response.to.have.status("Created");
});
Response body: Convert XML body to a JSON Object
var jsonObject = xml2Json(responseBody);
Use Tiny Validator for JSON data
var schema = {
    "items": {
        "type": "boolean"
    }
};
var data1 = [true, false];
var data2 = [true, 123];
pm.test('Schema is valid', function () {
    pm.expect(tv4.validate(data1, schema)).to.be.true;
    pm.expect(tv4.validate(data2, schema)).to.be.true;
});
More about array indexes CODE
It's possible to define keys only for some of the array items
$array = [1, 2, "name"=>"Three", 4];
print_r($array);
Result
Array
(
    [0] => 1
    [1] => 2
    [name] => Three
    [2] => 4
)
If we set higher index manually, it will continue adding 1 to the max index
$array = [1, 2, 7=>"Three", 4];
print_r($array);
Result
Array
(
    [0] => 1
    [1] => 2
    [7] => Three
    [8] => 4
)
If we set higher index manually, it will continue adding 1 to the index
$array = [1, 2, 7=>"Three", 4=>"forth", 25];
print_r($array);
Result
Array
(
    [0] => 1
    [1] => 2
    [7] => Three
    [4] => forth
    [8] => 25
)
Only integer and string values are allowed as array keys
$array = [
	1    => "a",
    "1"  => "b",
    "-1"  => "-b",
    '1.5'  => "c",
    true => "d",
];
print_r($array);
Result
Array
(
    [1] => d
    [-1] => -b
    [1.5] => c
)
Laravel could not read .env file
Solution to the problem:
composer dump-autoload
php artisan cache:clear
php artisan config:clear
php artisan view:clear
Make an object from a string
function mapString(string) {
  let map = {};
  for (let i = 0; i < string.length; i++) {
    let letter = string[i];
    if (map[letter]) {
      map[letter].push(i);
    } else {
      map[letter] = [i];
    }
  }
  return map;
}
console.log(mapString('blblllaaha'))
How FOR loop works
In the example code below the loop flows through these steps: Setting initial variable value of i to 0 Testing if the loop should be running while i is 0 Running the code block console.log(i) Updating i to be 1 Testing if the loop should be running while i is 1 Running the code block console.log(i) Updating i to be 2 Testing if the loop should be running while i is 2 This means the code will log 0 and 1 to the console.
for (let i = 0; i < 2; i++) {
   console​.log(i)
}
Results: 1024