簡體   English   中英

將當前目錄中的所有 imgs 放入數組 PHP

[英]put all imgs from current directory inside array PHP

我試圖將 all.PNG 文件放入包含詳細信息的數組中。

這是我的代碼:

$imgs = glob($path . "*.png");

$tab_img = [];

foreach($imgs as $value){
    $img_png = imagecreatefrompng($value);
    $tab_img['name'] = $value;
    $tab_img['width'] = imagesx($img_png);
    $tab_img['height'] = imagesy($img_png);
}

print_r($tab_img);

這是顯示的內容:

Array

    (
        [name] => ./sprite.png
        [width] => 300
        [height] => 300
    )

它只包含文件夾內的圖像,實際上還有更多...

在每個循環中,您將覆蓋數組中的相同元素,您應該構建圖像數據,然后將其添加到數組中......

$img_png = imagecreatefrompng($value);
$tab_img[] = [
    'name' => $value, 
    'width' => imagesx($img_png),
    'height' => imagesy($img_png),
];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM