# How To's ## Iterate an associative array (map) ```php foreach ($map as $key => $value) { echo "{$key} => {$value} "; print_r($arr); } ``` ## Use a lambda to map an array of objects into a string ```php $getVideoUrl = function($video) : string { return ""; }; ... $videoUrls = $listing->videos != null ? implode(",", array_map($getVideoUrl, $listing->videos)) : ""; ``` ## Getting request parameter and setting values * http://max/php-manual/reserved.variables.html * `$_SERVER` * http://max/php-manual/reserved.variables.server.html * `$_GET` * http://max/php-manual/reserved.variables.get.html (technically ALL params on the URL regardless of HTTP verb) * `$_POST` * http://max/php-manual/reserved.variables.post.html * `$_FILES` * http://max/php-manual/reserved.variables.files.html * `$_REQUEST` * http://max/php-manual/reserved.variables.request.html ``` // param value is null if missing $getParam = $_GET["paramName"]; $postParam = $_POST["paramName"]; $anyRequestParam = $_REQUEST["paramName"]; ``` # String Formatting ## Number-to-string Formatting source - https://www.php.net/manual/en/function.number-format.phphttps://www.php.net/manual/en/function.sprintf.php `$nextSkuOrdinal = sprintf("%03d", $row['nextSkuOrdinal']);`