doucepei5298 2019-02-27 16:57
浏览 34
已采纳

如何使用json解码添加不同的条件

$firstArray= [
    [
        "ID" => "ABC"
    ],
    [
        "ID" => "100"
    ],
    [
        "ID" => "200"
    ]
];

$firstArray= ["ABC" =>"fail"];

**Here I have to check two condition** 

Condition #1

$abc i am having 3 values, out of this values suppose present in $second array,we have ignore the value and remaining only one value we have to assign $existarray

As of now i have completed it is working fine also,

Condition #2

I have one more json like this

$jsonString = '{
    "jsonData" : {
        "ABC" : {
            "Count" :1
        },
         "100" : {
            "Count" :3
        },
        "200" : {
            "Count" :1
        }
    }
}';
$finalcount= json_decode($jsonString);

Now i want to check one more condition $abc array of mainarray key values count <10 we should ignore.This condition i have to implement my current code

Expected output

Array
(
    [ID] => 200
 )
  • 写回答

1条回答 默认 最新

  • douying6206 2019-02-27 17:27
    关注

    Merging 2 condition in if statement is done with &&.

    You can just mix those 2 condition in 1 for-loop:

    $jsonString = '{"jsonData" : {
            "ABC" : {"Count" :1},
            "100" : {"Count" :3},
            "200" : {"Count" :1}
        }
    }';
    $firstArray = json_decode($jsonString, true);
    
    $hobbies= [["ID" => "ABC"],["ID" => "100"],["ID" => "200"]];
    $books= ["ABC" => true];
    
    foreach ($Response as $key => $value) {
        $id = $value['ID'];
        if (!isset($books[$id]) && $firstArray["jsonData"][$id]["Count"] < 3 ) {
            $selectedItem = $value;
            break;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理