我有一個陣列,例如如何動態獲取數組鍵在php中檢查條件?
$test_input= array(
0=> array(
"task" => 'ColumnTree Example',
"duration" => '3 hours',
"user"=> '',
"uiProvider" => 'col',
"cls" => 'master-task',
"iconCls" => 'task-folder',
'children'=> array(
0 => array(
"task" => 'Abstract rendering in TreeNodeUI',
"duration" => '15 min',
"user" => 'Jack Slocum',
"uiProvider" => 'col',
"leaf" => true,
"iconCls" => 'task'
),
array(
"task" => 'Test and make sure it works',
"duration" => '1 hour',
"user" => 'Jack Slocum',
"uiProvider" => 'col',
"leaf" =>true,
"iconCls" =>'task'
)
)
),
array(
"task" => 'Custom Field Example',
"duration" => '2 1/2 hours',
"user" => '',
"uiProvider" => 'col',
"cls" => 'master-task',
"iconCls" => 'task-folder',
'children'=>array(
0 => array(
"task" =>'Implement "Live Search" on extjs.com from Alex',
"duration" =>'1 hour',
"user" =>'Jack Slocum',
"uiProvider" =>'col',
"leaf" =>true,
"iconCls"=> 'task'
),
array(
"task"=>'Extend TwinTrigger',
"duration"=>'30 min',
"user"=>'Jack Slocum',
"uiProvider"=>'col',
"leaf"=>true,
"iconCls"=>'task'
)
)
),
array(
"task"=>'Foo Bar Item',
"duration"=>'3 hours',
"user"=>'',
"uiProvider"=>'col',
"cls"=>'master-task',
"iconCls"=>'task-folder',
'children'=>array(
0 => array(
"task"=>'Abstract rendering in TreeNodeUI',
"duration"=>'15 min',
"user"=>'Jack Slocum',
"uiProvider"=>'col',
"leaf"=>true,
"iconCls"=>'task'
),
array(
"task"=>'Create TreeNodeUI with column knowledge',
"duration"=>'45 min',
"user"=>'Jack Slocum',
"uiProvider"=>'col',
"leaf"=>true,
"iconCls"=>'task'
)
)
)
);
我想要做一些東西。通過檢查條件
if($key=="task")
{
something/.........
}
所以在這裏,而不是靜態地給予鍵值爲「任務」。我需要這應該動態。 我正在使用array_map
來映射我的函數和我的數組。請給我一些關於如何做到這一點的例子。
可能是這樣的重複:http://stackoverflow.com/questions/5152694/php-referencing-a-dynamic-associative-array-position/5152747#5152747 – DhruvPathak 2011-03-25 07:37:27
請給我們一個如何使用它的例子。 – 2011-03-25 07:47:02
你使用哪個PHP版本?使用'foreach'可能更容易。 – 2011-03-25 07:47:55