在PHP中删除多维数组的部分

时间:2018-10-10 00:01:09

标签: php arrays

我有这个数组$ data:

Array
(
    [0] => 86086
    [1] => Arnel
    [2] => Paras
)
Array
(
    [0] => 86085
    [1] => Arnely
    [2] => Para
)
Array
(
    [0] => 

)

如何删除完全不包含任何值的底部数组,因此仅包含:

Array
(
    [0] => 86086
    [1] => Arnel
    [2] => Paras
)
Array
(
    [0] => 86085
    [1] => Arnely
    [2] => Para
)

我尝试使用array_filter($ data,strlen),它只是这样做:

Array
(

)

2 个答案:

答案 0 :(得分:0)

array_pop()弹出并返回数组的最后一个元素的值,将数组缩短一个元素,即可完成您所描述的操作。答:

array_shift()做相反的操作(从数组中删除第一个元素并返回值)

array_pop() on PHP.net

因此您可以执行以下操作:

$firstVal = array_pop($data)

或者只是

array_pop($data)

取决于是否要返回该值。

答案 1 :(得分:0)

可能会有帮助。

.586
.MODEL FLAT

INCLUDE io.h            ; header file for input/output

.STACK 4096

.DATA
 g1   DWORD   ?
 g2   DWORD   ?
 g3   DWORD   ?
 g4   DWORD   ?
 jj   BYTE  4
 prompt1 BYTE    "Enter grade 1", 0     
 prompt2 BYTE    "Enter grade 2", 0
 prompt3 BYTE    "Enter grade 3", 0
 prompt4 BYTE    "Enter grade 4", 0
 string  BYTE    40 DUP (?)
 resultLbl BYTE  "The average is", 0
 sum     BYTE    11 DUP (?), 0
 sum2    BYTE    11 DUP (?), 0

  .CODE
  MainProc PROC
        input   prompt1, string, 40      ; read ASCII characters
        atod    string          ; convert to integer
        mov     g1, eax    ; store in memory

        input   prompt2, string, 40      ; repeat for second number
        atod    string
        mov g2, eax

        input prompt3, string, 40        ;Repeat for third character
        atod string
        mov g3, eax

        input prompt4, string, 40        ;Repeat for third character
        atod string
        mov g4, eax

        mov eax, g1
        add eax, g2
        add eax, g3
        add eax, g4


       div jj


       dtoa    sum, eax        ; convert to ASCII characters
       output  resultLbl, sum         ; output label and sum

       mov     eax, 0  ; exit with return code 0
       ret
  _MainProc ENDP
  END                             ; end of source code