Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.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_Arrays_Multidimensional Array - Fatal编程技术网

要在PHP中使用多维数组中特定键的值吗

要在PHP中使用多维数组中特定键的值吗,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,我的数组是这样的: $x= Array( [0] => Array ( [0] => id [1] => 15 [2] => 0 ) [1] => Array ( [0] =>names [1] => 5 [2] => 1 ) ) 我想写一个语句,如果键[0]==id的值,那么做一些事情;否则,如果键[0]==名称的

我的数组是这样的:

$x= Array(

[0] => Array
    (
        [0] => id
        [1] => 15
        [2] => 0
    )

[1] => Array
    (
        [0] =>names
        [1] => 5
        [2] => 1
    )
)
我想写一个语句,如果键[0]==id的值,那么做一些事情;否则,如果键[0]==名称的值,请执行其他操作。
我有办法做到这一点吗?

谢谢。

使用foreach循环

    foreach($x as $key){  
         if ($key[0] == 'id') {  
              echo "Your id code will be here";  
         } else if ($key[0] == 'names') {  
              echo "Your names code will be here";  
         }    
    }  

我猜在数组中循环使用一个简单的if语句?!是的,你能做到。编写代码将是一个良好的开端。
foreach($x作为$y)如果($y[0]='id')…