trening - 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 trening.php
- <?php
- $input_arr = [
- "Program2/2021.03.21/INV20210310.1.7z",
- "Program2/2021.03.22/INV20210310.32.7z",
- "Program2/2021.03.21/INV20210310.22.7z",
- "Program2/2021.03.20/INV20210311.7.7z",
- "Program1/2021.03.21/INV20210310.1.7z",
- "Program1/2021.03.21/INV20210310.72.7z",
- "Program1/2021.03.21/INV20210310.22.7z",
- "Program1/2021.03.21/INV20210311.7.7z"
- ];
- function arrange_array(array $input_arr = []) :array {
- $assoc_array = [];
- $iterations = count($input_arr);
- for($x=0; $x<$iterations; $x++) {
- $row = explode_string_by_slash_to_array($input_arr[$x]);
- $assoc_array[$row[0]] = empty($assoc_array[$row[0]]) ? [] : $assoc_array[$row[0]];
- $assoc_array[$row[0]][$row[1]] = empty($assoc_array[$row[0]][$row[1]]) ? [] : $assoc_array[$row[0]][$row[1]];
- $separate_comma = explode_string_by_dot_to_array($row[2]);
- if(!isset($assoc_array[$row[0]][$row[1]][$separate_comma[0]])) {
- $assoc_array[$row[0]][$row[1]][$separate_comma[0]] = [];
- }
- $assoc_array[$row[0]][$row[1]][$separate_comma[0]] []= (int)$separate_comma[1];
- }
- foreach($assoc_array AS $program => $program_name) {
- foreach($program_name AS $date => $filename) {
- foreach($filename AS $key => $value) {
- sort($filename[$key]);
- $filename[$key]=$value;
- }
- ksort($filename);
- }
- ksort($program_name);
- //print_r($value);
- // sort($value);//sort by last number
- // ksort($value);//sort by file (before comma)
- //ksort($assoc_array[$program]);//sort date
- }
- //ksort($assoc_array);
- return $assoc_array;
- }
- function recurrent_sort(array $input_array) :array {
- foreach($input_array AS $key => $value) {
- if(is_array($value)) {
- $value = recurrent_sort($value);
- }
- sort($input_array);
- }
- return $input_array;
- }
- function explode_string_by_dot_to_array(string $input): array {
- return explode(".", $input);
- }
- function explode_string_by_slash_to_array(string $input): array {
- return explode("/", $input);
- }
- function create_array_element_if_not_exist($element = NULL) {
- if($element === NULL) {
- return [];
- }
- return $element;
- }
- //arrange_array($input_arr);
- print_r(arrange_array($input_arr));
- //print_r(arrange_array($input_arr))
File Description
- trening
- PHP Code
- 22 Mar-2021
- 2.28 Kb
You can Share it:
Latest PHP Pastes