如何从php多维数组中排除键?

问题描述 投票:0回答:1

我有一个允许我读取这样的csv文件的代码:

REFERENCE;COLOR;QUANTITY;TURNOVER;SELL TROUGH;COMMENT
GJK0C9;8952;3;90;3%;Pack S
GJKCS4;399;2;19;10%;Windows

并且这允许我浏览它并在这样的页面上显示csv信息:

enter image description here

但是我希望前两列“ REFERENCE”和“ COLOR”仅出现在每个图像的顶部,而不是输入。

如何将它们从阵列显示中排除?

<?php

$column = []; //create an array

        if (($handle = fopen("$nomcsv", "r")) !== FALSE) { 

                        // Get headers
                if (($data = fgetcsv($handle, 1000, ';')) !== FALSE)
                {
                    $column = $data; // assign header value to array
                }

                 // Get the rest
            while(($data = fgetcsv($handle, 1000000, ";")) !== FALSE) {

                    $file = '//Alcyons/it/PhotoShoot/Photos_Outil/'.$data[0].'_'.str_pad(trim($data[1]),4, "0", STR_PAD_LEFT).'-1.jpg';
                    $type = pathinfo($file, PATHINFO_EXTENSION);

                    echo "<tr><td valign=top><strong>".$data[0]."</strong><br><font color=\"#666666\">Color:</font>".$data[1]."
                    <div style=\"font-size:10px;\"><br>RRP:
                    <br><input type=text value=\"".$rrp."\" style=\"width:100px\">";

                    $row = array_combine($column,$data); // combine header with values
                    foreach($row as $key=>$value){

                        array_splice($key, 1, 1); //I tried this but doesn't work
                        echo "<br>$key:<br><input type=text value=\"".$value."\" style=\"width:100px\">";
                    } 

                    echo "</td><td valign=top align=center>";?><img src="<?php echo "data:image/$type;base64,",base64_encode(file_get_contents($file))?>""
                    <?php
                    echo "border=0 width=180></a></td><td width=10></td>";

                  }     

                }

?>
php foreach fgetcsv
1个回答
0
投票

您需要应用if来检查键并跳过打印这两个键(REFERENCECOLOR):

foreach($row as $key=>$value){

  if($key !=='REFERENCE' && $key !== 'COLOR'){
    echo "<br>$key:<br><input type=text value=\"".$value."\" style=\"width:100px\">";
  }
} 
© www.soinside.com 2019 - 2024. All rights reserved.