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

将PHP数组值转换为键值

将PHP数组值转换为键值,php,arrays,codeigniter,Php,Arrays,Codeigniter,我有下面的数组 <?php echo "<pre>"; print_r($row); ?> Array ( [0] => Array ( [contact] => ugin ) [1] => Array ( [contact] => gsGR ) [2] => Array

我有下面的数组

<?php
    echo "<pre>"; 
    print_r($row);
?>

Array
(
    [0] => Array
        (
            [contact] => ugin
        )

    [1] => Array
        (
            [contact] => gsGR
        )

    [2] => Array
        (
            [addtnlcontact] => ghjey
        )

)
Array
(
    [0] => Array
        (
            [relation] => uncle
        )

    [1] => Array
        (
            [relation] => mrsyjsrky
        )

    [2] => Array
        (
            [relation] => cghjrtdj
        )

)
我需要上面的信息应该在$row[0]=>contact=>ugin中 关系=>叔叔

请输入以下代码:

$addcont[]=$this->input->post(sheepItForm1\u addtnlcontact);
$this->conditionloop($addcont[0],'contact');
$relation[]=$this->input->post(sheepItForm1\u关系);
$this->conditionloop($relation[0],'relation');
公共函数条件循环($val,$name)
{
foreach($valas$key=>$res)
{
如果(!空($res)){
$row[$key][$name]=$res;
//echo“”;print_r($row[$key]);
}
}
echo“”;print_r($row[0]);
}

请帮助解决此问题

jagan检查答案并让我们知道最终状态?5天无响应,我将删除我的答案。不,它不起作用您预期的结果是什么?给我们看?检查我的答案输出链接,让我知道缺少什么?jagan检查答案,让我们知道最终状态?5天没有回应,我正在删除我的答案。不,它不起作用。你预期的结果是什么?给我们看?检查我的答案输出链接,让我知道那里缺少什么?
Array
(
    [contact] => ugin
)
Array
(
    [relation] => uncle
)
$addcont[] = $this->input->post(sheepItForm1_addtnlcontact);
$this->conditionloop($addcont[0],'contact');
$relation[] = $this->input->post(sheepItForm1_relationship);
$this->conditionloop($relation[0],'relation');
public function conditionloop($val,$name)
{
    foreach($val as $key => $res)
    {
        if(!empty($res)) {
            $row[$key][$name] = $res;
            //echo "<pre>"; print_r($row[$key]);
        }
    }
    echo "<pre>"; print_r($row[0]);
}