如何获取每个数组?

时间:2015-12-14 04:57:40

标签: php arrays

我的数组o / p是

Array ( [0] => Array ( [valueIdentifier] => LOGIN [valueMask] => LOGIN_FIELD)
 [1] => Array ( [valueIdentifier] => PASSWORD [valueMask] => LOGIN_FIELD [fieldType] .

我想要每个阵列,所以我尝试了这个

  foreach($myArray as $users){
       foreach($users as $user){
           echo $x=$user['valueIdentifier'];
       }
  }

我得到了输出:LOGINPASSWORD。我想得到输出LOGIN,PASSWORD SEPERATE。所以我这样做了:

echo $x=$user[0]['valueIdentifier'];
echo $x=$user[1]['valueIdentifier'];

但我没有得到答案。

2 个答案:

答案 0 :(得分:0)

嵌套foreach上的Concat逗号;它会告诉你你想要的东西

foreach($myArray as $users){
   foreach($users as $user){

       echo $user['valueIdentifier'].',';
   }
}

输出将是:

LOGIN,PASSWORD,

答案 1 :(得分:0)

    <?php
        $arr_final = array();

        $arr = array (
                        0 => array (
                                        'valueIdentifier' => 'LOGIN',
                                        'valueMask' => 'LOGIN_FIELD'
                                    ),
                        1 => array (
                                        'valueIdentifier' => 'PASSWORD',
                                        'valueMask' => 'LOGIN_FIELD'
                                    )
                    );
        /* SCENARIO 1 */
        foreach( $arr as $key_arr => $value_arr )
            {
                $arr_final[] = $value_arr['valueIdentifier'];
            }

        if(!empty($arr_final))
            echo implode(', ', $arr_final);

        /* SCENARIO 2 */
        echo "<p>&nbsp;</p>";
        echo $arr[0]['valueIdentifier'];
        echo $arr[1]['valueIdentifier'];

        exit();

    ?>