获得多维数组的价值

时间:2018-01-22 11:14:14

标签: php

如果tran2

,我的回答应为tran3tran4name = transport_method

例如: -

Array ( 
   [0] => Array ( [name] => transport_method[] [value] => tran2 ) 
   [1] => Array ( [name] => transport_method[] [value] => tran3 ) 
   [2] => Array ( [name] => transport_method[] [value] => tran4 ) 
) 

2 个答案:

答案 0 :(得分:1)

使用if()

foreach()应用于所需的条件检查
foreach($array as $arr){
  if($arr['name'] =='transport_method[]'){
    echo $arr['value'];
   }
}

请检查所有三项输出: - https://eval.in/939902https://eval.in/939909以及https://eval.in/939911

答案 1 :(得分:0)

<?php
    foreach($yourvariable as $data) {
      if($data['name'] == "transport_method"){
      echo $data['value'];
    }
}