<?
porter
download all .zip
examples/basics.php
<?php $name = "World"; $items = array('apple', 'banana', 'cherry'); $prices = ['apple' => 1.5, 'banana' => 0.25]; function greet(string $who, int $times = 1): string { $out = ''; for ($i = 0; $i < $times; $i++) { $out .= "Hello, $who! "; } return trim($out); } echo greet($name, 2); echo "We have " . count($items) . " items"; foreach ($prices as $fruit => $price) { if ($price > 1) { $label = 'pricey'; } elseif ($price > 0.5) { $label = 'fair'; } else { $label = 'cheap'; } echo "{$fruit} is $label"; } $upper = array_map(fn($i) => strtoupper($i), $items); echo implode(', ', $upper);
examples/basics.js
copy
download
// ported from php with porter. review before shipping. let label; let name = "World"; let items = ['apple', 'banana', 'cherry']; let prices = {'apple': 1.5, 'banana': 0.25}; function greet(who, times = 1) { let i; let out = ''; for (i = 0; i < times; i++) { out += `Hello, ${who}! `; } return out.trim(); } console.log(greet(name, 2)); console.log("We have " + items.length + " items"); for (const [fruit, price] of Object.entries(prices)) { if (price > 1) { label = 'pricey'; } else if (price > 0.5) { label = 'fair'; } else { label = 'cheap'; } console.log(`${fruit} is ${label}`); } let upper = items.map((i) => i.toUpperCase()); console.log(upper.join(', '));
Check by hand
1
echo became console.log. in a web app, build a string and send it with res.send() instead