Loop through an array php

前端 未结 5 876
故里飘歌
故里飘歌 2020-11-22 17:13

I have this array... how do you print each of the filepath and filename? What is the best way to do this?

  Array ( 
    [0] => Array ( 
             [fid         


        
5条回答
  •  一生所求
    2020-11-22 17:53

    Ok, I know there is an accepted answer but… for more special cases you also could use this one:

    array_map(function($n) { echo $n['filename']; echo $n['filepath'];},$array);
    

    Or in a more un-complex way:

    function printItem($n){
        echo $n['filename'];
        echo $n['filepath'];
    }
    
    array_map('printItem', $array);
    

    This will allow you to manipulate the data in an easier way.

提交回复
热议问题