Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 搜索数组值_Php - Fatal编程技术网

Php 搜索数组值

Php 搜索数组值,php,Php,大家好,我有下面的数组。我需要根据Id值修改所有值。我怎样才能做到这一点 Array ( [0] => Array ( [Id] => 2 [Description] => Get first Description [Code] => GF [Value] => 1.0 ) [1] => Array ( [Id] => 3 [Des

大家好,我有下面的数组。我需要根据
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
    )
试着

foreach($my_arr as $arr) {
   $new_arr[$arr['ID']] = $arr['Value'];
}
print_r($new_arr);

已编辑

$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' ) );

你到底想做什么?您需要一些函数来搜索这些数组吗?上面的数组来自我的数据库表。现在,我需要自定义它(即,如果我只需要
Id
3的描述和值,我如何做而不是使用全局变量将数组作为第二个参数)。@DeiForm注意不同,但已编辑:)好吧。。。我将asnwer设置为与您的相同,因为我看到您只返回1个值,但似乎您设置为与我相同:D@DeiForm不,在第一次编辑中修复了它:DYe没有看到要删除我的答案:)