2017-02-23 20:50
浏览 28


I want to iterate over a CSV file and check if on position row[1] are certain countries. If yes, the while lap should be skipped to the next row.

But at the moment it is failing due to my if condition:

$countries = array("Österreich", "Schweiz", "Niederlande", "Großbritannien", "United States");

while (($row = fgetcsv($inputFile, 0, $delimiter)) !== false) {
        foreach ($countries as $country){
            if(((stripos($row[1], $country === false))) && stripos($row[0], "Card")){
                echo $row[0] . "\t => \t" . $row[1] . "
... some other code (Dealing with the values) ...     

To continue coding I was checking if my statement is right and if I get the desired values. But I do not.

I want only to get the values where the country is not one of the countries in the array and if the title in row[1] contains the word card. But if I use this if condition I get no values. But what is wrong?

This is a CSV sample:

"PlayStation Network Card 20€";"Deutschland ";
"PlayStation Network Card 50€";Österreich;
"Playstation Plus Live Card - 365 Tage";Deutschland;
"PlayStation Network Card 10£ ";Großbritannien;
"PlayStation Network Card 20$";"United States";

So actual I should get "PlayStation Network Card 20€";"Deutschland "; and "Playstation Plus Live Card - 365 Tage";Deutschland;. But I do not...

Does anybody know why and if yes how can I fix that?

And my second question is: If one value of products_edition is matching with one country from my array, the actual while lap should get skipped because I do not want to handle the product if it is from those countries. But how can I tell that that actual while lap?

I do not want to stop the hole while loop, only the while lap where row[1] is matching one of the countries in my country array.

Does anybody has an idea? Greetings and Thank You!

EDIT: I know now how to skip the actual loop lap and to tell the loop to continue with the next lap. I just use continue;. But there is still my other if condition problem... :/

图片转代码服务由CSDN问答提供 功能建议

我想迭代一个CSV文件并检查位置行[1]是否是某些国家/地区。 如果是,那么应该跳到下一行。


 <  code> $ countries = array(“Österreich”,“Schweiz”,“Niederlande”,“Großbritannien”,“United States”); 
而(($ row = fgetcsv($ inputFile,0,$ delimiter))!  == false){
 foreach($ countries as $ country){
 if(((stripos($ row [1],$ country === false)))&amp;&amp; stripos($ row [0]  ,“卡”)){
 echo $ row [0]。  “\ t =&gt; \ t”。  $ row [1]。  “

继续 编码我正在检查我的陈述是否正确以及我是否得到了所需的值。 但我不这样做。

我只想得到国家不是数组中某个国家/地区的值,以及 row [1]中的标题包含一词。 但如果我使用这个条件我没有得到任何价值。 但是有什么问题?


  products_name; products_edition 
“PlayStation Network Card 20€”;“Deutschland”; 
  “PlayStation Network Card 50€”;Österreich; 
“Playstation Plus Live Card  -  365 Tage”; Deutschland; 
“PlayStation Network Card 10£”;Großbritannien; 
“PlayStation Network Card 20 $”;“United States”  ; 

实际上我应该“PlayStation Network Card 20€”;“Deutschland”; “Playstation Plus Live 卡 - 365 Tage“;德国; 。 但是我没有......


我的第二个问题是: 如果 products_edition 的一个值与我的数组中的一个国家匹配,实际的圈数应该被跳过,因为如果来自这些国家我不想处理该产品。 但是我怎么能在圈速时说出那个实际值呢?

我不想在循环时停止这个洞,只是在 row [1] 所在的那一圈。 匹配我的国家/地区阵列中的一个国家/地区。

是否有人有想法? Greetings and Thank You!

编辑:< / strong> 我现在知道如何跳过实际的循环圈并告诉循环继续下一圈。 我只是使用 continue; 。 但是仍有我的其他if条件问题......:/

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douya5194 2017-02-23 21:22
    $countries = array("Österreich", "Schweiz", "Niederlande", "Großbritannien", "United States");
    while (($row = fgetcsv($inputFile, 0, $delimiter)) !== false) {
        if (in_array($row[1], $countries) && strpos($row['1'], "Card") !== false) {
        echo $row[0] . "\t => \t" . $row[1] . "
    //... some other code (Dealing with the values) ...     
    解决 无用
    打赏 举报

相关推荐 更多相似问题