大家好,我有以下数组。我需要基于Id
值的所有值。我怎么能这样做。
Array
(
[0] => Array
(
[Id] => 2
[Description] => Get first Description
[Code] => GF
[Value] => 1.0
)
[1] => Array
(
[Id] => 3
[Description] => Get second Description
[Code] => GF
[Value] => 1.0
)
[2] => Array
(
[Id] => 4
[Description] => Get third Description
[Code] => GF
[Value] => 1.0
)
答案 0 :(得分:0)
尝试
foreach($my_arr as $arr) {
$new_arr[$arr['ID']] = $arr['Value'];
}
print_r($new_arr);
答案 1 :(得分:0)
<强>被修改强>
$array = array(
array(
'Id' => '1',
'Description' => 'Get first Description',
'Code' => 'GF',
'Value' => 'Test 1'
),
array(
'Id' => '2',
'Description' => 'Get second Description',
'Code' => 'GF',
'Value' => 'Test 2'
),
array(
'Id' => '3',
'Description' => 'Get third Description',
'Code' => 'GF',
'Value' => 'Test 3'
)
);
function getArrayValue( $array , $id )
{
foreach( $array as $a )
{
if( $a['Id'] == $id )
{
return $a;
}
}
return 'U/N';
}
print_r( getArrayValue( $array , '2' ) );