3v4l.org

run code in 300+ PHP versions simultaneously
<?php // https://forum.pasja-informatyki.pl/507316/php-tablice-wyjatki $input = ["Witam","mam","tablice","zeszyt","dwuwymiarową w PHP.", "ołówek","Potrzebuję","kredka1","ze zbioru","umieścić na początku."]; // --- Demo --- echo "Orginalna wejściowa tablica".PHP_EOL; print_r($input).PHP_EOL; echo PHP_EOL; echo implode(" ",$input); echo PHP_EOL.PHP_EOL; echo "Przefiltrowana wejściowa tablica".PHP_EOL; $new_input = twojaNazwa($input); print_r($new_input); echo PHP_EOL; echo implode(" ",$new_input); function twojaNazwa($input) { $searched = ["ołówek","kredka","zeszyt"]; // Zwraca tablicę słów szukanych (z $searched), które są w $input $found_searched = array_intersect($input,$searched); // Wyrzucamy z $searched słowa, które nie zostały znalezione w $input // i reindeksujemy tablice $found_searched, żeby indeks zaczynał sie od n0, n+1 $clean_found_searched = array_merge(array_intersect($found_searched,$searched)); // Wrzucamy z $input znalezione ($searched), za pomocą $clean_found_searched // i reindeksujemy nową zawartość tablicy $input $clean_input = array_merge(array_diff($input,$clean_found_searched)); // Dodajemy na początku nowego $clean_input -> $clean_found_searched $new_input = array_merge($clean_found_searched,$clean_input); return $new_input; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/06qup
function name:  (null)
number of ops:  29
compiled vars:  !0 = $input, !1 = $new_input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, <array>
    9     1        ECHO                                                     'Orginalna+wej%C5%9Bciowa+tablica%0A'
   10     2        INIT_FCALL                                               'print_r'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        CONCAT                                           ~4      $3, '%0A'
          6        FREE                                                     ~4
   11     7        ECHO                                                     '%0A'
   12     8        INIT_FCALL                                               'implode'
          9        SEND_VAL                                                 '+'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $5      
         12        ECHO                                                     $5
   13    13        ECHO                                                     '%0A%0A'
   14    14        ECHO                                                     'Przefiltrowana+wej%C5%9Bciowa+tablica%0A'
   15    15        INIT_FCALL_BY_NAME                                       'twojaNazwa'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0  $6      
         18        ASSIGN                                                   !1, $6
   16    19        INIT_FCALL                                               'print_r'
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                                 
   17    22        ECHO                                                     '%0A'
   18    23        INIT_FCALL                                               'implode'
         24        SEND_VAL                                                 '+'
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                         $9      
         27        ECHO                                                     $9
   34    28      > RETURN                                                   1

Function twojanazwa:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/06qup
function name:  twojaNazwa
number of ops:  30
compiled vars:  !0 = $input, !1 = $searched, !2 = $found_searched, !3 = $clean_found_searched, !4 = $clean_input, !5 = $new_input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        ASSIGN                                                   !1, <array>
   24     2        INIT_FCALL                                               'array_intersect'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !2, $7
   27     7        INIT_FCALL                                               'array_merge'
          8        INIT_FCALL                                               'array_intersect'
          9        SEND_VAR                                                 !2
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $9      
         12        SEND_VAR                                                 $9
         13        DO_ICALL                                         $10     
         14        ASSIGN                                                   !3, $10
   30    15        INIT_FCALL                                               'array_merge'
         16        INIT_FCALL                                               'array_diff'
         17        SEND_VAR                                                 !0
         18        SEND_VAR                                                 !3
         19        DO_ICALL                                         $12     
         20        SEND_VAR                                                 $12
         21        DO_ICALL                                         $13     
         22        ASSIGN                                                   !4, $13
   32    23        INIT_FCALL                                               'array_merge'
         24        SEND_VAR                                                 !3
         25        SEND_VAR                                                 !4
         26        DO_ICALL                                         $15     
         27        ASSIGN                                                   !5, $15
   33    28      > RETURN                                                   !5
   34    29*     > RETURN                                                   null

End of function twojanazwa

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.16 ms | 1405 KiB | 23 Q