2016-05-14 7 views
0

I次の配列を持つ関連するアレイ内の各キーから一つの値をフェッチ

array(
    'messages' => array(
     0 => array(
      'id' => '3', 
      'subject' => 'what did you say last night?', 
      'message' => 'your mother wai', 
      'from' => '13', 
      'to' => '1', 
      'from_viewed' => '0', 
      'to_viewed' => '0', 
      'from_deleted' => '0', 
      'to_deleted' => '0', 
      'from_vdate' => NULL, 
      'to_vdate' => NULL, 
      'from_ddate' => NULL, 
      'to_ddate' => NULL, 
      'created' => '2016-05-14 14:02:12', 
     ) , 
     1 => array(
      'id' => '2', 
      'subject' => 'this is new', 
      'message' => 'hello guy', 
      'from' => '11', 
      'to' => '1', 
      'from_viewed' => '0', 
      'to_viewed' => '0', 
      'from_deleted' => '0', 
      'to_deleted' => '0', 
      'from_vdate' => NULL, 
      'to_vdate' => NULL, 
      'from_ddate' => NULL, 
      'to_ddate' => NULL, 
      'created' => '2016-05-14 13:59:56', 
     ) , 
     2 => array(
      'id' => '1', 
      'subject' => 'hello boy.', 
      'message' => 'i love this too much . what do you think about making this happen for tomorrow? already then . good bye', 
      'from' => '11', 
      'to' => '1', 
      'from_viewed' => '0', 
      'to_viewed' => '0', 
      'from_deleted' => '0', 
      'to_deleted' => '0', 
      'from_vdate' => NULL, 
      'to_vdate' => NULL, 
      'from_ddate' => NULL, 
      'to_ddate' => NULL, 
      'created' => '2016-05-14 13:54:02', 
     ) , 
    ) , 
) 

私がやりたいすべてが、この場合は、アレイ内のすべてのキーの値(「から」それは取ることです - 13,11,11)、それらをデータベースに送信して、コードネイターで名前やアバターなどの情報を取得します。

UPDATE

Iは次のようにしようと、ITは、(バックでカンマで)、MEを11,11,13を与えました。

$from = $messages['messages']; 


     for ($col = 0; $col < 3; $col++) { 
     echo $messages['messages'][$col]['from'].","; 
     } 

さらに、いくつの値をエコーする必要があるか判断したくありません。私はそれが存在する限りエコーするようにしたい。

+0

ここに 'var_dump()'配列を入れてください。 –

答えて

2

あなたは13,11,11としてそれが出力するこの

$t = array(
    'messages' => array() 
) 
/// your array ...... 

$from = ''; 
foreach($t['messages'] as $k => $m){ 
    if($k == 0){ 
     $from = $m['from']; 
    }else{ 
     $from .= ','.$m['from']; 
    } 
} 
echo $from; 

を使用することができます。しかし、それらの値の配列が必要な場合は、次のように使用できます。

$from = array(); 
foreach($t['messages'] as $k => $m){ 
     $from[] = $m['from']; 

} 
print_r($from); 
+1

をテストできるように、 'var_export()'配列を指定してください。あるいは、$ [$ k] 'に具体的なメッセージキーをバインドしておくこともできます。 – Tpojka

+0

ありがとう、この '$ t = array( 'messages' => array() ); ///あなたの配列...... $ from = $ messages ['messages']; foreach($ t ['messages'] $ k => $ m){ $ from [] = $ m ['from']; } print_r($ from); '空の配列だけを出力する - array(); –

+0

次のものは、** 13,13。** '$ t = array( 'messages' => array() )を出力します。 ///あなたの配列...... $ from = $ messages ['messages'] [0] ['from']; foreach($ t ['messages'] $ k => $ m){ if($ k == 0){ $ from = $ m ['from']; } else { $ from。= '、'。$ m ['from']; } } echo $ from; print_r($ from); '。値を配列に結合するのはいいですので、処理のためにデータベースに送ることができます。ありがとう –