sample code - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of sample code.php
- <?php
- function solve(array $problem) {
- $length = $problem['number'];
- $datas = $problem['datas'];
- $cost = 0;
- for ($i=0; $i < $length-1; $i++) {
- echo "i=$i;";
- $k = $j = i;
- while ($k < $length) {
- echo "j=$j;";
- if ($datas[$k] > $datas[$i]) {
- $j = $k;
- }
- $j++;
- }
- $iteration_cost = (($j - $i) + 1);
- $cost += $iteration_cost;
- for ($k = $i; $k < ($i + $iteration_cost/2); $k++) {
- echo "k=$k;";
- $ech = $datas[$k];
- $datas[$k] = $datas[($j - ($k - $i))];
- $datas[($j - ($k - $i))] = $ech;
- }
- exit();
- }
- return $cost;
- }
- echo solve(['number' => 4, 'datas' => [4,2,1,3]]);
File Description
- sample code
- PHP Code
- 28 Mar-2021
- 766 Bytes
You can Share it:
Latest PHP Pastes