Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

php - Multidimensional Array: Extract second value if first is present

I have a multidimensional array:

array(3) {
  ["checkIn"]=>  array(0) {}
  ["code"]=> array(0) {}
  [0]=> array(2) { 
        ["checkIn"]=> string(10) "2021-02-02"
        ["code"]=>string(10) "00Q4K00"
      }
}

which I initialize in this way:

$array= array(
    'checkIn'=>array(),
    'code'=>array()
    );

and so I value:

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $array[] = array('checkIn'=>$row['checkIn'], 'code'=>$row['code']);
  }

I can't figure out how to extract 'code' if '2021-02-02' is present:

if ( in_array('2021-02-02', array_column($array, 'checkIn')) ){
   echo code??
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...