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

PHP在变量中保存数组结果

PHP在变量中保存数组结果,php,arrays,Php,Arrays,假设我有这样一个数组: $testarray = array('abc'=>'123', 'def'=>'456', 'ghi'=>'789' ); new cmdOption("cn", $arrayvaluefirstcolumn, "User") new cmdOption("mod", "text=".$arraysecondcolumn, "expression") 对于操作,我需要变量中数组的单个值。我想

假设我有这样一个数组:

$testarray = array('abc'=>'123',
              'def'=>'456',
              'ghi'=>'789'
);
new cmdOption("cn", $arrayvaluefirstcolumn, "User")

new cmdOption("mod", "text=".$arraysecondcolumn, "expression")
对于操作,我需要变量中数组的单个值。我想在数组中循环,得到如下内容:

$testarray = array('abc'=>'123',
              'def'=>'456',
              'ghi'=>'789'
);
new cmdOption("cn", $arrayvaluefirstcolumn, "User")

new cmdOption("mod", "text=".$arraysecondcolumn, "expression")
因此,我希望在第一个循环中使用'abc'作为$arrayvaluefirstcolumn,使用'123'作为$arrayvaluesecondcolumn。在第二个循环中,我希望将'def'作为$arrayvaluefirstcolum,将'456'作为$arrayvaluesecondcolumn,依此类推


我不知道如何循环数组以获得所需的结果并将其存储在变量中。这可能吗?你能给我一些建议吗?

你唯一需要做的就是在数组中循环

$testarray = array(
    'abc' => '123',
    'def' => '456',
    'ghi'=>'789'
);

foreach ($testArray as $key => $value) {
    new cmdOption("cn", $key, "User");
    new cmdOption("mod", "text=".$value, "expression");
}
可能重复的